[ACCEPTED]-Visually count up to number on page load-timer
Accepted answer
How does this work for you?
Change the 50
at 2 the end of the setTimeout function to change 1 the speed it counts in miliseconds.
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
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.
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?
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.