我面临的问题是我无法弄清楚如何使动画条与百分比 I 同步。现在我看起来还可以,但是当我将值“43”更改为“100”时,百分比计数器变慢。
示例代码:
$(document).ready(function(){
$(".barInner").animate({
width: 43 + "%",
opacity: 1
}, 2500 );
var display = $('.barInner');
var currentValue = 0;
var nextValue = 43;
var diff = nextValue - currentValue;
var step = ( 0 < diff ? 1 : -1 );
for (var i = 0; i < Math.abs(diff); ++i) {
setTimeout(function() {
currentValue += step
display.text(currentValue + "%");
}, 54 * i)
}
});
提前致谢,
缺口