js 显示数字不断增加

一个小小的函数,很容易看懂,就不过多解释了,只为下次用时直接用就ok了。。。

function countUp(count)
        {
            var div_by = 100,
                speed = Math.round(count / div_by),
                $display = $('.count'),
                run_count = 1,
                int_speed = 24;

            var int = setInterval(function() {
                if(run_count < div_by){
                    $display.text(speed * run_count);
                    run_count++;
                } else if(parseInt($display.text()) < count) {
                    var curr_count = parseInt($display.text()) + 1;
                    $display.text(curr_count);
                } else {
                    clearInterval(int);
                }
            }, int_speed);
        }

        countUp(num);

只需要把要显示内容的元素获取下来,还有把要显示的数据写到函数的参数位置即可。。

原文地址:https://www.cnblogs.com/wanglaowu/p/6524145.html