I would like to know (if possible) how to use a unit of time less than milliseconds in the setInterval
or setTimeout
functions.
I made a progressive timer using the following code
function timer(){
if(counter < qntLinhas){
counter++;
$("#quantidade").text(counter);
}
if(counter > qntLinhas){
counter -= 1;
$("#quantidade").text(counter);
}
}
setInterval("timer()", 0);
The variable qntLinhas
is referring to the result of an AJAX query that returns an X value.
It works very well, however, when the value of qntLines is too high, it takes a while to arrive at the end result, and it is boring to wait.
To circumvent this, I made two consecutive increments in the counter variable, but in addition to being gambiarra, the final result is not accurate.
I tried to use the countTo plugin and the time issue was resolved, but another problem came up. It does not allow me to update the value, which I want to achieve in counting, at runtime (via AJAX).