该代码不能完美地处理较大的数字?有人可以解释为什么吗?有时会,有时不会?
$('.Count').each(function () {
var $this = $(this);
jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
duration: 1000,
easing: 'swing',
step: function () {
$this.text(Math.ceil(this.Counter));
}
});
});
最佳答案
不一定会为序列中的每个可能的数字调用 step
回调。
将此添加到 .animate
的 options
参数中:
complete: function () {
$this.text(Math.ceil(this.Counter));
}
这可确保显示最终值。请参阅http://jsfiddle.net/3qfjta79/
关于javascript - 为什么此脚本不适用于更大的数字/值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26128027/