Skip to content

Instantly share code, notes, and snippets.

@Brunty
Created May 11, 2015 09:39
Show Gist options
  • Save Brunty/2430b69e0fe4c22529ed to your computer and use it in GitHub Desktop.
Save Brunty/2430b69e0fe4c22529ed to your computer and use it in GitHub Desktop.
Only perform actions after window has finished resizing
/*
By default, $(window).resize() will fire every time the window is resized, so for each pixel it moves, it's called.
This isn't necessarily always needed and some things can be left to when the window has finished resizing.
We don't have a (native) way of doing this, but with this little snippet you can achieve basically what we want.
*/
var windowResize;
$(window).resize(function() {
// Clear the timeout each time the window is resized
clearTimeout(windowResize);
// Start the timeout - after 500ms if the window hasn't been resized again it'll call our finishedResizing() function
windowResize = setTimeout(finishedResizing, 500);
});
function finishedResizing() {
// here we can do things that we want to do after the window has finished resizing.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment