数字不断递增 可控制js

(function($){
    $.fn.numberRock=function(options){
        var defaults={
            speed:24,
            count:100
        };
        var opts=$.extend({}, defaults, options);

        var div_by = 100,
        count=opts["count"],
        
        speed = Math.floor(count / div_by),
        sum=0,
        $display = this,
        run_count = 1,
        int_speed = opts["speed"];
        var int = setInterval(function () {
            if(count == 0){
                $display.text(0);
            }
            if (run_count <= div_by&&speed!=0) {
                $display.text(sum=speed * run_count);
                run_count++;
            } else if (sum < count) {
                $display.text(++sum);
            } else {
                clearInterval(int);
            }
        }, int_speed);
    }

})(jQuery);

这是个count.js  这个函数定义了数字的大小和速度,所以说以后只要根据自己需求 分别填写大小和速度即可;

$(".value").numberRock({
             speed:34,
             count:1
	})

好好玩耍吧
posted @ 2017-03-28 15:14  王老五Plus  阅读(1599)  评论(0编辑  收藏  举报