Last active
May 6, 2024 05:18
-
-
Save danro/7846358 to your computer and use it in GitHub Desktop.
underscore throttle using requestAnimationFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yairEO is right.