Skip to content

Instantly share code, notes, and snippets.

@bezenson
Last active October 9, 2017 12:21
Show Gist options
  • Save bezenson/11344593 to your computer and use it in GitHub Desktop.
Save bezenson/11344593 to your computer and use it in GitHub Desktop.
Wait while event will end
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);
};
})();
$(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