Skip to content

Instantly share code, notes, and snippets.

@lean8086
Created August 25, 2012 03:58
Show Gist options
  • Save lean8086/3460474 to your computer and use it in GitHub Desktop.
Save lean8086/3460474 to your computer and use it in GitHub Desktop.
Updated requestAnimationFrame pollyfill
var lastTime = 0,
currTime,
timeToCall,
id;
window.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
function (callback) {
currTime = new Date().getTime();
timeToCall = Math.max(0, 16 - (currTime - lastTime));
id = window.setTimeout(function () { callback(currTime + timeToCall); }, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
window.cancelAnimationFrame = window.cancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.msCancelAnimationFrame ||
window.oCancelAnimationFrame ||
function (id) {
window.clearTimeout(id);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment