Skip to content

Instantly share code, notes, and snippets.

@ryanriatno
Created December 20, 2014 21:17
Show Gist options
  • Save ryanriatno/a559d4eb8986c126227b to your computer and use it in GitHub Desktop.
Save ryanriatno/a559d4eb8986c126227b to your computer and use it in GitHub Desktop.
Fire $(window).resize() function after the browser window resize is completed
// http://stackoverflow.com/a/4541963
var waitForFinalEvent = (function () {
var timers = {};
return function (callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = "Don't call this twice without a uniqueId";
}
if (timers[uniqueId]) {
clearTimeout (timers[uniqueId]);
}
timers[uniqueId] = setTimeout(callback, ms);
};
})();
// Usage
$(window).resize(function () {
waitForFinalEvent(function(){
alert('Resize...');
//...
}, 500, "some unique string");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment