Last active
November 7, 2016 20:55
-
-
Save arxpoetica/4644738 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(window) { | |
var _lastTime = 0; | |
window.requestAnimationFrame = | |
window.requestAnimationFrame || | |
function(callback) { | |
var currTime = new Date().getTime(); | |
var timeToCall = Math.max(0, 16 - (currTime - _lastTime)); | |
var id = window.setTimeout(function() { | |
callback(currTime + timeToCall); | |
}, timeToCall); | |
_lastTime = currTime + timeToCall; | |
return id; | |
}; | |
window.cancelAnimationFrame = | |
window.cancelAnimationFrame || | |
function(id) { | |
clearTimeout(id); | |
}; | |
window.performance = performance || {}; | |
window.performance.now = window.performance.now || function() { return new Date().getTime(); }; | |
}(window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If throttling is needed:
https://twitter.com/arxpoetica/status/224355470444474368
http://stackoverflow.com/questions/19000109/javascript-cant-adjust-framerate-requestanimationframe
http://stackoverflow.com/questions/19764018/controlling-fps-with-requestanimationframe