Skip to content

Instantly share code, notes, and snippets.

@nosp4mSnippets
Created June 23, 2013 22:10
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nosp4mSnippets/5846729 to your computer and use it in GitHub Desktop.
Save nosp4mSnippets/5846729 to your computer and use it in GitHub Desktop.
JS: wait final event
// Here's a modification of CMS's solution that can be called in multiple places in your code:
// Wait for final event example during resize
//
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