[ACCEPTED]-Visually count up to number on page load-timer

Accepted answer
Score: 11

How does this work for you?

http://jsfiddle.net/WpJxn/1/

Change the 50 at 2 the end of the setTimeout function to change 1 the speed it counts in miliseconds.

Score: 3

I'd replace the while with a setInteval

$(function() {
    $(".statRibbon .bigStat span").each(function() {
        var that = $(this),
            tmp = that.html(),
            i = 0,
            interval;

        that.html(0);
        interval = setInterval(function() {
            that.html(++i);
            if (i === +tmp) clearInterval(interval);
        }, 50);
    });
});​

0

Score: 3

If someone wants to increase counter with 3 certain increment then use,

// HTML

<span class="stat-count">10000</span>

// JS

$(function() {
    function count($this){
        var current = parseInt($this.html(), 10);
        current = current + 50; /* Where 50 is increment */

    $this.html(++current);
    if(current > $this.data('count')){
        $this.html($this.data('count'));
    } else {    
        setTimeout(function(){count($this)}, 5);
    }
}        

$(".stat-count").each(function() {
  $(this).data('count', parseInt($(this).html(), 10));
  $(this).html('0');
  count($(this));
 });

});

Jquery 2 count numbers on page load with certain 1 limit, counting time and counting increment.

Score: 1

It appears to me that you need some kind 4 of sleep or delay in your loop before or 3 after you alert the number. Try the setTimeout method.

You 2 can find more information in this question 1 here: Jquery: how to sleep or delay?

More Related questions