Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

javascript - 尝试以“ Counter”动画时返回错误的值(Returned wrong value when trying to animate as “Counter”)

I'm trying to animate with "Counter" animation some values that i get from my API by using the following method every time the data from API is changed:

(每当API的数据发生更改时,我都会使用以下方法为“ Counter”动画制作动画,这些动画是通过以下方法从API获取的:)

 $('.count').each(function () {
        var $this = $(this);
        jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
            duration: 1000,
            easing: 'swing',
            step: function () {
                $this.text(this.Counter.toFixed(2));
            }
        });
    });

The issue is that original value given by API in the following question is 396718.760 so formatted should be 396718.76 but when i'm animating it with the above function it return all times different values as you can see here

(问题是,API在以下问题中给出的原始值为396718.760,因此格式应为396718.76,但是当我使用上述函数对其进行动画处理时,它将返回所有不同的值,如您在此处看到的)

在此处输入图片说明

So how can i fix it by returning the right value?

(那么如何通过返回正确的值来解决它?)

  ask by Igor Mytyuk translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...