Created
October 1, 2012 19:38
-
-
Save tdreyno/3813974 to your computer and use it in GitHub Desktop.
One-off animation with rAF
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
function oneOffAnimation(from, to, duration, easing, onUpdate, onComplete) { | |
var t = new TWEEN.Tween(from) | |
.to(to, duration) | |
.easing(easing) | |
.onUpdate(onUpdate) | |
.onComplete(function _onComplete() { | |
t.done = true; | |
}); | |
var self = this; | |
function tick(ts) { | |
if (!ts) { | |
ts = +(new Date()); | |
} | |
t.update(ts); | |
if (t.done) { | |
onComplete(); | |
} else { | |
requestAnimationFrame(tick); | |
} | |
} | |
t.start(); | |
requestAnimationFrame(tick); | |
return t; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment