Skip to content

Instantly share code, notes, and snippets.

@zachfedor
Last active August 29, 2015 14:16
Show Gist options
  • Save zachfedor/c572e34cb7744d674a6d to your computer and use it in GitHub Desktop.
Save zachfedor/c572e34cb7744d674a6d to your computer and use it in GitHub Desktop.
$(window).resize(function(){
waitForFinalEvent(function(){
yourFunction();
}, 500, "unique id");
});
/**************************************
*// Wait For It...
**************************************/
var waitForFinalEvent = (function () {
var timers = {};
return function (callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = "Do not call this twice without a uniqueId";
}
if (timers[uniqueId]) {
clearTimeout (timers[uniqueId]);
}
timers[uniqueId] = setTimeout(callback, ms);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment