Created
February 22, 2011 14:50
-
Star
(160)
You must be signed in to star a gist -
Fork
(26)
You must be signed in to fork a gist
-
-
Save mrdoob/838785 to your computer and use it in GitHub Desktop.
Provides requestAnimationFrame in a cross browser way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Provides requestAnimationFrame in a cross browser way. | |
* @author paulirish / http://paulirish.com/ | |
*/ | |
if ( !window.requestAnimationFrame ) { | |
window.requestAnimationFrame = ( function() { | |
return window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.oRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { | |
window.setTimeout( callback, 1000 / 60 ); | |
}; | |
} )(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@buttflattery I know this is an old post, but I'm replying for any future people who see this. You use
1000 / 60
because it results to around16.667
milliseconds. If you were to use this number, it would call the render function almost exactly 60 times per second, meaning 60 FPS. You could easily do1000 / 80
to get 80 FPS if you really wanted, but 60 FPS is a common number for monitor refresh rates. If you were to use1000
as the delay, then you would only get 1 frame per second.