Last active
October 9, 2017 12:21
-
-
Save bezenson/11344593 to your computer and use it in GitHub Desktop.
Wait while event will end
This file contains 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
var debounce = (function () { | |
var timers = {}; | |
return function (callback, ms, uniqueId) { | |
if (!uniqueId) { | |
uniqueId = 'default'; | |
} | |
if (timers[uniqueId]) { | |
clearTimeout(timers[uniqueId]); | |
} | |
timers[uniqueId] = setTimeout(callback, ms); | |
}; | |
})(); |
This file contains 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
$(window).resize(function() { | |
debounce(function() { | |
// action | |
}, 500, 'resize'); // wait 0.5s after resize | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment