我已经能够使用this code从零开始对数字进行动画处理:
$('.count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
但是,我需要用逗号显示我的电话号码,例如
30,000,000
。当我这样做时,此代码将失败。有没有简单的方法可以使其与这种格式一起使用? 最佳答案
你可以加
.toLocaleString('en')
到步骤属性:
step: function(now) {
$(this).text(Math.ceil(now).toLocaleString('en'));
}
您也可以传入navigator.language而不是'en',并且小数点将根据用户浏览器的语言设置显示。