I am using jqClock as a plugin to show ti开发者_StackOverflowme in my web application, and keith wood countdown to show the remaining time. My question is if some of you had a problem with them not being synced? Like for example if the time is 15:40:00 and the countdown should count down until 15:41:00 (so basically it should count down 1 minute). Then for example my jqclock shows 15:40:30 and countdown shows 31 (instead of 30 - and this is ugly to see on screen cause I want the timers to change their values simultaneously). Any help would really be godsend as I've spent ages on this :(
edit: The more I think about this I think it would be better to remove the jqClock plugin and update the clock manually in the onTick event of the keith plugin.. But would really like to hear thoughts of people who may have had the same problem...
Disclaimer: i never used jqClock or keith plugin.
Depending on how the conting is done, the js timers may drift. The internal js setTimeout function is not guaranteed to sleep the the exact amount of time specified. The smallest time it can sleep depends on the operating system+browser(and possibly on the client hardware, as really old systems didn't have hpets, or cpu counters). The function should be regarded more as "sleep at least this amount of time, then execute my handler". For example, a setTimeout(2000) will end up sleeping 10seconds if the system is busy, instead of 2 seconds. Now, if the 2 plugins use different timers and handling techniques they will surely drift away...
As you said, i'd a better ideea to use a single "heartbeat" and sync all stuff from that one source.
精彩评论