I want to fire a recursive function every 10 milliseconds, but setTimeout doesn't seem to take any value under 100, no matter what I put.
decrementCountdown = function() {
console.log('fired');
t = setTimeout("decrementCountdown()", 100);
}
Why can't I set a value under 1000 milliseconds?
EDIT : Looks like my timer is firing correctly...the problem is when I use it to call a function ( like Jquery's html() ). Even though setTimeout is calling the function at correct intervals, it won't fire any faster than 100 milliseconds.
Anyone know how I can make a countdown timer on my page that counts down by 10 milliseconds?
A better example is:
var stop = 0;
decrementCountdown = function() {
console.log(new Date().getTime());
stop++;
if (stop<10) t = setTimeout("decrementCountdown()", 100);
}
decrementCountdown();
As you should see, the timeout is triggered about every 100ms (jsFiddle).
I tried your example and it seemed to work fine.
For what it's worth I'd save on the constant redeclaration of setTimeout by using
function decrementCountdown()
{
/*Do your thing*/
}
setInterval(decrementCountdown, 100);
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