Skip to content

Instantly share code, notes, and snippets.

@corycook
Created April 24, 2018 17:34
Show Gist options
  • Select an option

  • Save corycook/670858df7e90e597ea384832395e3b41 to your computer and use it in GitHub Desktop.

Select an option

Save corycook/670858df7e90e597ea384832395e3b41 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