-2
I would like to know (if possible) how to use a unit of time less than milliseconds in the functions setInterval
or setTimeout
.
I made a progressive stopwatch 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 me an X value.
It works very well, However, when the value of qntLines is very high, it takes a little to get the final result and, even be boring to wait.
To circumvent this, I made two increments in a row in the counter variable, but in addition to being a gambiarra, the final result is not necessary.
I tried using the plugin countTo and the question of time was resolved, but another problem arose. It does not allow me to update the value, which I want to achieve in the count, at runtime (via AJAX).
Can you explain further the idea of progressive chronometer and how it should interact with ajax? to be honest I don’t understand what problem you’re trying to solve
– Sergio
Why are you using 0 in the timer? It’s only by the desired value there. For example 60000 for a minute.
– Bacco
http://clayderson.com.br/ take a look at this page, you’ll understand. the end value of the counter is set at run time with ajax. That chronometer is updated every 30 seconds with a new value (if applicable).
– Clayderson Ferreira
@Bacco, I want a value less than 0 milliseconds, not higher.
– Clayderson Ferreira
If you just want the answer to what you asked, it’s simple: "there’s no way". But I’m pretty sure the problem isn’t in the timer, only it’s hard to help without you explaining the problem that has to be solved, rather than the way you think it’s going to solve. Reading suggestion: What is the XY problem. Once we know the problem, we can propose solutions without needing the timer less than milliseconds.
– Bacco
PS: If it’s the comment counter, it’s even simpler, just don’t count from 1 to 1, and make an exponential curve to be cool (starting to skip a larger amount, and decreasing the interval when getting close to the value). And in this case, edit the question and add this detail, because in the comment normally visitors will not be looking for details.
– Bacco