timer function

Discussion in 'Javascript' started by Dr John Stockton, Nov 10, 2004.

  1. JRS: In article <>, dated Tue, 9 Nov
    2004 19:20:03, seen in news:comp.lang.javascript, Darren Showers
    <> posted :
    >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 .

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Nov 10, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H @ Q
    Replies:
    0
    Views:
    459
    H @ Q
    May 31, 2004
  2. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    719
    Kelsang Wangchuk
    Jul 31, 2003
  3. Replies:
    1
    Views:
    1,618
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,216
    Bruce Barker
    Nov 4, 2005
  5. Replies:
    8
    Views:
    513
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page