Skip to content

Instantly share code, notes, and snippets.

@toruta39
Last active December 22, 2015 00:18
Show Gist options
  • Save toruta39/6387908 to your computer and use it in GitHub Desktop.
Save toruta39/6387908 to your computer and use it in GitHub Desktop.
Normalize requestAnimationFrame
// Normalize requestAnimationFrame
var fps = 30;
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
return setTimeout(callback, 1000 / fps);
};
var cancelAnimationFrame = window.cancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.msCancelAnimationFrame ||
function (timer) {
return clearTimeout(timer);
};
window.requestAnimationFrame = requestAnimationFrame;
window.cancelAnimationFrame = cancelAnimationFrame;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment