我正在尝试对0到36.6之间的数字进行动画处理,但是目前还没有运气,因为它只是将最终值四舍五入为37,如您在此处的小提琴中所见:http : //jsfiddle.net/neal_fletcher/0f3hxej8/
以下是必要的标记:
HTML
<div id="el"></div>
jQuery的:
// Animate the element's value from x to y:
$({someValue: 0}).animate({someValue: 36.6}, {
duration: 3000,
easing:'swing', // can be anything
step: function() { // called on every step
// Update the element's text with rounded-up value:
$('#el').text(commaSeparateNumber(Math.round(this.someValue)));
},
complete:function(){
$('#el').text(commaSeparateNumber(Math.round(this.someValue)));
}
});
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.");
}
return val;
}
理想情况下,我希望它也可以通过小数点进行动画处理,例如35.9、36.0、36.1、36.2等。任何建议将不胜感激!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句