JS函数计数器不输出正确的数字

时间:2017-06-28 09:58:42

标签: javascript jquery

最后缺少两位数,为什么? Javascript output is in white and the desired numbers are in black above

enter image description here

Js代码:

$('.count').each(function () {
    $(this).prop('Counter', 0).animate({
        Counter: $(this).text()
    }, {
        duration: 1000,
        easing: 'swing',
        step: function (now) {
            $(this).text(now);
        }
    });
});

2 个答案:

答案 0 :(得分:1)

你需要保持尾随零选择显示多少位数(使用toFixed(n))。以下示例中的三位小数:

on

https://jsfiddle.net/o2gxgz9r/9319/

答案 1 :(得分:-1)

使用

解决它
$(this).text(valueOf(now));

而不是:

$(this).text(now);