Non-linear “animation” of numeric value with JavaScript/jQuery

前端 未结 1 1907
梦谈多话
梦谈多话 2020-12-21 10:50

I want to make an animation like this one in Google Analytics on active users.

\"Analytics


I saw
相关标签:
1条回答
  • 2020-12-21 11:27

    I would use jQuery's built-in animation for this.

    If you pass a function to the step option for .animate(), it will be fired for each tick during animation. That way, jQuery will handle all of the easing and what not for you. You just need to handle the data.

    $({countValue:0}).animate(
        {countValue:346},
        {
            duration: 5000, /* time for animation in milliseconds */
            step: function (value) { /* fired every "frame" */
                console.log(value);
            }
        }
    );
    

    In the console, you will see values between 0 and 346, complete with easing.

    0 讨论(0)
提交回复
热议问题