Skip to content

Instantly share code, notes, and snippets.

@alegut
Created July 12, 2018 11:03
Show Gist options
  • Select an option

  • Save alegut/e6b957361227126e1aa304c9fdf02e96 to your computer and use it in GitHub Desktop.

Select an option

Save alegut/e6b957361227126e1aa304c9fdf02e96 to your computer and use it in GitHub Desktop.
Detect final of resize event
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);
};
})();
$(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