To better understand how you can use the step
[as posted by gdoron]
function, I created an example using the step function to get the remaining time:
(click the button get state!to stop the animation and get the remaining time!)
demo with distance demo with opacity
JQuery distance example:
var time = 4000;
var distance = 300;
var currentTime = 0;
$('#ball').animate({
left: distance
}, {
duration: time,
step: function (now, fx) {
currentTime = Math.round((now * time) / distance);
var data = fx.prop + ' ' + Math.round(now) + '; <b>' + currentTime + 'ms</b> ';
$('body').append('<p>' + data + '</p>');
},
easing: 'linear'
});
$('#getTime').click(function () {
$('#ball').stop();
$('body').prepend('<p>currentTime is:' + currentTime + ' ms; REMAINING: ' + (time - currentTime) + 'ms</p>');
});
- ,
fx.prop animation step, (left), .
- , : (, ...), "/" (
(now*time)/distance) now .