Skip to content

Instantly share code, notes, and snippets.

@danro
Last active May 6, 2024 05:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danro/7846358 to your computer and use it in GitHub Desktop.
Save danro/7846358 to your computer and use it in GitHub Desktop.
underscore throttle using requestAnimationFrame
// Returns a function, that, when invoked, will only be triggered once every
// browser animation frame - using tram's requestAnimationFrame polyfill.
// tram.js - https://github.com/bkwld/tram
_.throttle = function(func) {
var wait, args, context;
return function () {
if (wait) return;
wait = true;
args = arguments;
context = this;
window.tram.frame(function () {
wait = false;
func.apply(context, args);
});
};
};
@towry
Copy link

towry commented Jun 21, 2016

yairEO is right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment