public
Last active

generic time-based tween with easing support

  • Download Gist
tween.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
!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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.