我需要在90秒内制作动画
我在其中使用了.animate()
函数和step选项。
当还剩0秒时,它变为0,但是数字并没有每秒减少!
请参阅this fiddle
function timeRunner() {
$("#TimeIndicator").animate({
width: "0px"
}, {
duration: 90000,
step: function (now) {
var percent = (Math.round(now) / 136) * 100;
var timeleft = (percent) * (0.9);
$("#TimeIndicator").html(Math.round(timeleft));
},
complete: function () {
timerReset();
}
})
};
function timerReset() {
$("#TimeIndicator").animate({
width: "136px"
}, 0, function () {
timeRunner();
});
};
最佳答案
因为动画的easing的默认设置是swing
。将其设置为linear
关于javascript - 使用step选项的.animate()函数不会使计数器每秒减少一次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20185691/