Aar*_*ron 0 javascript jquery number-formatting
所以这个脚本计算到我添加到跨度的数字,但我想在 11,000 之后添加一个逗号。
如果尝试添加toFixed但没有帮助:
$(this).text(Math.ceil(now).toFixed(3));
$('.counter').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 7000,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now));
stop();
$(this).removeClass('counter');
}
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="number">
<span class="count counter">100</span>
</div>
<div class="number">
<span class="count counter">11000</span>
</div>Run Code Online (Sandbox Code Playgroud)
你可以使用toLocalString():
$('.counter').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 7000,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now).toLocaleString());
// Here --------------------^
stop();
$(this).removeClass('counter');
}
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="number">
<span class="count counter">100</span>
</div>
<div class="number">
<span class="count counter">11000</span>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
305 次 |
| 最近记录: |