Skip to content

Instantly share code, notes, and snippets.

@AmesianX
Forked from corycook/throttle.js
Created March 19, 2019 20:39
Show Gist options
  • Select an option

  • Save AmesianX/fa4bceea1748da01708cd2e21ee4dadb to your computer and use it in GitHub Desktop.

Select an option

Save AmesianX/fa4bceea1748da01708cd2e21ee4dadb to your computer and use it in GitHub Desktop.
A simple throttle function.
function throttle(fn) {
let waiting = false;
return function() {
if (!waiting) {
waiting = true;
requestAnimationFrame(() => {
waiting = false;
fn.apply(this, arguments);
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment