Skip to main content

The basic idea is that you don't want to be hammering the window resize event because it gets fired repeatedly when a user manually resizes their browser. Instead you should use a short timeout to wait for resizing to end.

var resizeTimeout, $win = $(window);
$win.on('resize', function () {
  if (resizeTimeout) {
    clearTimeout(resizeTimeout);
  }
  
  resizeTimeout = setTimeout(function () {
    // do stuff here
  }, 100);
});