Last active
August 29, 2015 14:19
-
-
Save ezhlobo/0dc0415e37d2ab66b963 to your computer and use it in GitHub Desktop.
Debounced resize events
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
/* | |
smartresize(function() { | |
// Handle the resize event here | |
}); | |
// Executing after loading | |
smartresize(function() { | |
// Handle the resize event here | |
})(); | |
*/ | |
window.smartresize = function(callback, timer) { | |
window.addEventListener('resize', function() { | |
clearTimeout(timer); | |
timer = setTimeout(callback, timer); | |
}, false); | |
return callback; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment