jQuery animated number counter from zero to value

后端 未结 10 767
天涯浪人
天涯浪人 2020-11-28 04:00

I have created a script to animate a number from zero to it\'s value.

Working

jQuery

10条回答
  •  广开言路
    2020-11-28 04:22

    What the code does, is that the number 8000 is counting up from 0 to 8000. The problem is, that it is placed at the middle of quite long page, and once user scroll down and actually see the number, the animation is already dine. I would like to trigger the counter, once it appears in the viewport.

    JS:

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

    And HTML:

     8000
    

提交回复
热议问题