Keeping compatibility
suggest changeUnprefixed requestAnimationFrame is standard in current browsers. Older WebKit and Gecko builds exposed webkitRequestAnimationFrame and mozRequestAnimationFrame. This fallback covers those names:
window.requestAnimationFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();
setTimeout does return an id, but cancelAnimationFrame does not clear a timeout, and the callback does not receive the timestamp that requestAnimationFrame passes. A fuller polyfill is at https://gist.github.com/paulirish/1579671. That gist was not rechecked for this edition.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents