【发布时间】:2021-02-24 07:43:42
【问题描述】:
我是 JS 的初学者,不知道如何在这里完成。想法是在数字中有逗号,以便在计数时更容易阅读,并且最终的静态结果也应该有逗号。
例如:“10,000”
var a = 0;
$(window).scroll(function() {
var oTop = $('#counter').offset().top - window.innerHeight;
if (a == 0 && $(window).scrollTop() > oTop) {
$('.counter-value').each(function() {
var $this = $(this),
countTo = $this.attr('data-count');
$({
countNum: $this.text()
}).animate({
countNum: countTo
},
{
duration: 2000,
easing: 'swing',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);
//alert('finished');
}
});
});
a = 1;
}
});
【问题讨论】:
-
stackoverflow.com/questions/2901102/… ,希望这能回答你的问题
-
将数字转换为字符串并插入逗号。
标签: javascript counter