Javascript 计数器从滚动开始

我需要这个计数器从滚动开始,而不是之前。是否可以?


function startCounter(){

    $('.counter').each(function (index) {

        $(this).prop('Counter',0).animate({

            Counter: $(this).text()

        }, {

            duration: 2000,

            easing: 'swing',

            step: function (now) {

                $(this).text(Math.round(now*10)/10);

            }

        });

    });

}   


startCounter();

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<span class="counter">92.2</span>


郎朗坤
浏览 138回答 2
2回答

牧羊人nacy

这将为您做到。window.addEventListener('scroll', function(e) {&nbsp; &nbsp; startCounter();});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript