Skip to content

Instantly share code, notes, and snippets.

@mrlemoos
Created July 12, 2022 18:42
Show Gist options
  • Save mrlemoos/c416c5adde672e1fab9eb00be27364de to your computer and use it in GitHub Desktop.
Save mrlemoos/c416c5adde672e1fab9eb00be27364de to your computer and use it in GitHub Desktop.
Throttle function (JavaScript Vanilla)
let throttlePaused = false;
function throttle(callback, time) {
if (throttlePaused) {
return;
}
throttlePaused = true;
setTimeout(() => {
callback();
throttlePaused = false;
}, time);
}
module.exports = throttle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment