timer function

D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 9 Nov
2004 19:20:03, seen in Darren Showers
I'm running a timer function that counts down from set time frames.
It has an odd tendency to drop 2 seconds at the beginning but then
work fine the rest of the way. Can anyone suggest what could be
happening here?

if (running) {
timerID = setTimeout("showCountDown()",1000)
}

That gives a delay of 1000 ms, rounded up to the next clock tick; there
will also be the delay in executing the code that precedes it.

You need to calculate the delay to the next second, or say 10% of the
way through it, as for example

setTimeout("Tock()", 1100-D%1000)

where D = new Date().

Read the c.l.j newsgroup FAQ; see below; see js-date0.htm#TaI .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top