Skip to content

Instantly share code, notes, and snippets.

@LarryAnomie
Last active December 25, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarryAnomie/6980669 to your computer and use it in GitHub Desktop.
Save LarryAnomie/6980669 to your computer and use it in GitHub Desktop.
Delay the firing of the window resize event
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
waitForFinalEvent(function () {
// do something cool after resize here
}, 500, "some unique string");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment