I have three counters, which go up to a certain number, defined as data-count-to
of each tag, my problem here is that I liked them to reach their limit at the same time, even with values as different as is the case below:
function count_up(ele, count_to, timer, i) {
if(i > count_to) {
return;
}
ele.text(i.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
i += 1;
/*console.log(timer);*/
setTimeout(function() {count_up(ele, count_to, timer, i)}, timer);
}
$('.counter-up').each(function() {
count_to = parseInt($(this).data('countTo'));
timer = parseInt(40000/count_to);
count_up($(this), count_to, timer, 0)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><spanclass="counter-up" data-count-to="5684"></span>
</div>
<div>
<span class="counter-up" data-count-to="6603146"></span></div>
<div>
<span class="counter-up" data-count-to="20362"></span>
</div>
Now, I think my problem is math in this case, because I suspect you have to also tweak the amount to increase as well, not just in time.
I would like the final result to be just that the argument to vary is the time, but with as long as the three counters come to the end of it at the same time