Created
May 13, 2011 06:07
-
-
Save ded/970065 to your computer and use it in GitHub Desktop.
generic time-based tween with easing support
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
!function ($) { | |
function tween(duration, from, to, tween, ease) { | |
ease = ease || function (t) { | |
return t; | |
} | |
var self = this, | |
time = duration || 1000, | |
animDiff = to - from, | |
startTime = new Date(), | |
timer = setInterval(animate, 5); | |
function animate () { | |
var diff = new Date() - startTime; | |
if (diff > time) { | |
tween(to); | |
clearInterval(timer); | |
timer = null; | |
return; | |
} | |
tween((animDiff * ease(diff / time)) + from); | |
} | |
} | |
$.ender({tween: tween}); | |
}(ender) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment