Created
October 14, 2015 12:31
-
-
Save fedyk/274be24d9958889c84dc to your computer and use it in GitHub Desktop.
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
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