我已经创建了一个脚本来动画一个数字从零到它的值。
在职的
jQuery
$({ Counter: 0 }).animate({
Counter: $('.Single').text()
}, {
duration: 1000,
easing: 'swing',
step: function() {
$('.Single').text(Math.ceil(this.Counter));
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="Single">150</span>
不工作
我现在想为每个匹配的类在页面上多次运行脚本。
以下是我正在尝试但迄今为止没有成功的内容:
HTML
<span class="Count">200</span>
<span class="Count">55</span>
查询
$('.Count').each(function () {
jQuery({ Counter: 0 }).animate({ Counter: $(this).text() }, {
duration: 1000,
easing: 'swing',
step: function () {
$(this).text(Math.ceil(this.Counter));
}
});
});