how to animate numbers using Jquery

后端 未结 8 745
时光取名叫无心
时光取名叫无心 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条回答
  •  再見小時候
    2021-02-02 03:10

    Untested - but should work along these lines

    create the HTML like this:

    earn $233 without working hard

    and jQuery like this:

    function increment(){
        $('#counter').text(parseFloat($('#counter').text())+1)
        if(parseFloat($('#counter').text()) < 250){ setTimeout(increment,100) }
    }
    increment()
    

提交回复
热议问题