最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSjQuery number increasing animation - Stack Overflow

programmeradmin15浏览0评论

Let's say i have a div called .number containing a number.

i want to increase that number to a new one dynamically with a counter increasing effect like this one in the bottom.

Any lightweight solutions?

Thanks

Let's say i have a div called .number containing a number.

i want to increase that number to a new one dynamically with a counter increasing effect like this one in the bottom.

Any lightweight solutions?

Thanks

Share Improve this question asked Dec 12, 2010 at 21:21 CodeOverloadCodeOverload 48.5k56 gold badges133 silver badges223 bronze badges 1
  • Where's the number coming from, and in what way is it 'dynamic'? – David Thomas Commented Dec 12, 2010 at 21:24
Add a comment  | 

1 Answer 1

Reset to default 17
$(function() {
  var ele = $('#haha');
  var clr = null;
  var rand = (Math.random() * 100000) >> 0;
  (loop = function() {
    clearTimeout(clr);
    (inloop = function() {
      ele.html(rand+=1);
      if(!(rand % 50)) {
        return;
      }
      clr = setTimeout(inloop, 30);
    })(); 
    setTimeout(loop, 2500);
  })();
});

DEMO

Edit :

$(function () {
    var ele = $('#haha');
    var clr = null;
    var rand = Math.floor(Math.random() * 100000); // just a random number(initial number)
    loop();
    function loop() {
        clearTimeout(clr);
        inloop();
        setTimeout(loop, 2500); //call 'loop()' after 2.5 seconds
    }
    function inloop() {
        ele.html(rand += 1);
        if (!(rand % 50)) {
            return;
        }
        clr = setTimeout(inloop, 30); //call 'inloop()' after 30 milliseconds
    }
});

$(function() {
  var ele = $('#haha');
  var clr = null;
  var rand = (Math.random() * 100000) >> 0;
  (loop = function() {
    clearTimeout(clr);
    (inloop = function() {
      ele.html(rand += 1);
      if (!(rand % 50)) {
        return;
      }
      clr = setTimeout(inloop, 30);
    })();
    setTimeout(loop, 2500);
  })();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="haha"></div>

发布评论

评论列表(0)

  1. 暂无评论