Created
August 6, 2015 16:53
-
-
Save atsea/924fc40dbfec0d8e9623 to your computer and use it in GitHub Desktop.
jQuery: fire event AFTER window resize is complete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* | |
* 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