Skip to content

Instantly share code, notes, and snippets.

@drzhbe
Created May 16, 2013 10:27
Show Gist options
  • Save drzhbe/5590808 to your computer and use it in GitHub Desktop.
Save drzhbe/5590808 to your computer and use it in GitHub Desktop.
// shim layer with setTimeout fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
// usage:
// instead of setInterval(render, 16) ....
(function animloop(){
requestAnimFrame(animloop);
render();
})();
// place the rAF *before* the render() to assure as close to
// 60fps with the setTimeout fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment