Created
May 18, 2013 11:50
-
-
Save mfields/5604160 to your computer and use it in GitHub Desktop.
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
/** | |
* Simple animation loop with start and stop controls. | |
*/ | |
var animationFrameId; | |
/** | |
* Animation Loop. | |
* | |
* @uses animationFrameId | |
* @uses requestAnimationFrame() | |
*/ | |
function animate() { | |
animationFrameId = window.requestAnimationFrame( animate ); | |
render(); | |
} | |
/** | |
* Start the animation. | |
* | |
* @uses animationFrameId | |
* @uses animate() | |
*/ | |
function start() { | |
if ( ! animationFrameId ) | |
animate(); | |
} | |
/** | |
* Stop the animation. | |
* | |
* @uses animationFrameId Sets the value of id to undefined. | |
* @uses cancelAnimationFrame() to stop the animation. | |
*/ | |
function stop() { | |
if ( animationFrameId ) { | |
animationFrameId = window.cancelAnimationFrame( animationFrameId ); | |
animationFrameId = undefined; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment