Skip to content

Instantly share code, notes, and snippets.

@mattzeunert
Created September 8, 2020 17:00
Show Gist options
  • Save mattzeunert/568ca537e18b15401ccae88cb07ba002 to your computer and use it in GitHub Desktop.
Save mattzeunert/568ca537e18b15401ccae88cb07ba002 to your computer and use it in GitHub Desktop.
function throttle (callback, limit) {
var wait = false;
return function () {
if (!wait) {
callback.apply(null, arguments);
wait = true;
setTimeout(function () {
wait = false;
}, limit);
}
}
}
window.addEventListener('resize', throttle(function(e){console.log(e)}, 100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment