I have a a counter that needs to count up from $0 to $10,000 in x seconds (most likely 3 seconds).
Just straight text, kind of like a millisecond countdown timer, but upwards and with a dollar sign.
I'd rather not use a bulky plugin as this just needs to loop through 1-10,00 in x seconds and update every 100ms or so.
I'm stuck at creating the loop that will update, where should I start?
Here is what I've got so far on a click event:
function countUp() {
console.log('counted');
}
setInterval("countUp()", 1000)
Using jQuery (edited):
$(function(){
var current = 0;
var finish = 10000;
var miliseconds = 3000;
var rate = 20;
var counter = setInterval(function(){
if(current >= finish) clearInterval(counter);
$("#div").text("$" + current);
current = parseInt(current) + parseInt(rate);
}, miliseconds / (finish / rate));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With