Skip to content

Instantly share code, notes, and snippets.

@arxpoetica
Last active November 7, 2016 20:55
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 arxpoetica/4644738 to your computer and use it in GitHub Desktop.
Save arxpoetica/4644738 to your computer and use it in GitHub Desktop.
(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));