【发布时间】:2013-04-20 02:54:44
【问题描述】:
我正在尝试增加页面元素内的数字。但我需要在数字中包含一个逗号作为千位值。 (例如 45,000 而不是 45000)
<script>
// Animate the element's value from x to y:
$({someValue: 40000}).animate({someValue: 45000}, {
duration: 3000,
easing:'swing', // can be anything
step: function() { // called on every step
// Update the element's text with rounded-up value:
$('#el').text(Math.round(this.someValue));
}
});
</script>
<div id="el"></div>
如何使用带逗号的动画来增加数字?
【问题讨论】:
-
我会将数字存储在数据属性中,然后在元素中显示数字的逗号格式版本。当你增加它时,只需增加数据版本并替换格式化版本。
-
这可能会对你有所帮助 - stackoverflow.com/questions/1990512/…
标签: jquery jquery-animate increment comma easing