Skip to content

Instantly share code, notes, and snippets.

@fedyk
Created October 14, 2015 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedyk/274be24d9958889c84dc to your computer and use it in GitHub Desktop.
Save fedyk/274be24d9958889c84dc to your computer and use it in GitHub Desktop.
function eventThrottler(callback) {
if (!callback) {
return callback;
}
// @see http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
var requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
return function() {
if (!callback.__timeout) {
callback.__timeout = requestAnimFrame(function() {
callback.__timeout = null;
callback.apply(this, arguments);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment