假设我有一些div,我用.animate({opacity:0},400, function(){});它的孩子.那么有可能让动画的剩余时间完成吗?例如,剩余200毫秒,如果没有动画则为0?谢谢.
为了帮助您更好地理解如何使用step函数[由gdoron发布]
我使用step 函数创建了一个示例来获取剩余时间:
(单击get state!按钮停止动画并检索剩余时间!)
距离示例jQuery:
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>');
});
Run Code Online (Sandbox Code Playgroud)
fx.prop内部animation step来获取left当前动画的()属性.
(now*time)/distance)轻松检索"已停止/暂停"状态,并感谢返回的now值.| 归档时间: |
|
| 查看次数: |
2863 次 |
| 最近记录: |