how to animate numbers using Jquery

后端 未结 8 751
时光取名叫无心
时光取名叫无心 2021-02-02 02:31

I am trying to animate a say $233 to $250 or decreasing from 250 to 233 ,i dont want to replace 233 by 250 instead i want a counter kind of effect and at the time of scrolling

8条回答
  •  梦毁少年i
    2021-02-02 03:12

    @Denis. The second answer has some problem,I change the code as follows:

    // Animate the element's value from 0% to 110%:
    jQuery({someValue: 0}).animate({someValue: 110}, {
        duration: 1000,
        easing:'swing', // can be anything
        step: function(now) { // called on every step
            // Update the element's text with rounded-up value:
            $('#el').text(Math.ceil(now) + "%");
        }
    });
    

    This will avoid the precision question.

提交回复
热议问题