Created
May 11, 2015 09:39
-
-
Save Brunty/2430b69e0fe4c22529ed to your computer and use it in GitHub Desktop.
Only perform actions after window has finished resizing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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