Skip to content

Instantly share code, notes, and snippets.

@atsea
Created August 6, 2015 16:53
Show Gist options
  • Save atsea/924fc40dbfec0d8e9623 to your computer and use it in GitHub Desktop.
Save atsea/924fc40dbfec0d8e9623 to your computer and use it in GitHub Desktop.
jQuery: fire event AFTER window resize is complete
*
* Hide site search drop down and default to sites.udel.edu/<site> search. 5/27/15 CL
* http://bigwilliam.com/jquery-fire-event-after-window-resize-is-completed/
* https://gist.github.com/atsea/3f53c9ceca40277918da
*/
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() {
var output = $('.output');
$(output).text('RESIZING...');
// Wait for it...
waitForFinalEvent(function() {
$(output).text('EVENT FIRED!');
//...
}, 500, "some unique string");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment