Skip to content

Instantly share code, notes, and snippets.

@jeromeetienne
Forked from paulirish/gist:839879
Created May 18, 2011 17:23
Show Gist options
  • Save jeromeetienne/979055 to your computer and use it in GitHub Desktop.
Save jeromeetienne/979055 to your computer and use it in GitHub Desktop.
requestAnimFrame() shim.
// see http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// shim layer with setTimeout fallback
(function(){
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback, element){
return window.setTimeout(function(){
callback(+new Date);
}, 1000 / 60);
};
})();
window.cancelRequestAnimFrame = (function() {
return window.cancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout
})();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment