Created
April 11, 2013 14:48
-
-
Save mattisfrommars/5363987 to your computer and use it in GitHub Desktop.
Wrapper for requestAnimationFrame that accepts a callback and duration. Gives the callback a "completion" value between 0 and 1 every animation frame
This file contains hidden or 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
| var animateObject = function (callback, duration) { | |
| var startTime = 0; | |
| var slideFrame = function(animationMiliSeconds) { | |
| startTime = startTime || animationMiliSeconds; | |
| var timeTaken = animationMiliSeconds - startTime; | |
| var completion = timeTaken / duration; | |
| if (animationMiliSeconds <= startTime+duration) { | |
| callback(completion); | |
| requestAnimationFrame(slideFrame); | |
| } else { | |
| callback(1); | |
| } | |
| } | |
| requestAnimationFrame(slideFrame); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment