Javascript Count Up
- Started
- Last post
- 11 Responses
- dbloc
I am looking for a javascript counter that counts days minutes and seconds. Starts at 0 and counts up. and when it reaches the goal it's stops and calls a function. It's for a timed event.
Anyone seen anything like this?
- dbloc0
like a stop watch
- Stugoo0
i guess you could use a simple timer like this
http://stuntsnippets.com/javascr…but reverse the start time and end time and have the time increase to a point.
a quick google returns this
http://css-tricks.com/forums/dis…
- dbloc0
http://css-tricks.com/forums/dis…
this one restarts on refresh. I need it to work off the time.start at 7:00 and start counting up
- Hombre_Lobo0
^sounds like php / asp is the best way to go, like spot13, server side will be easier. no idea how to though :/
- dbloc0
not sure how to do that either
- dbloc0
this one works.
- monNom0
you can grab the UTC time on load, subtract from the target time (in UTC), and start from there. The only issue is if the user's clock is incorrect (in which case you could pass UTC time from server as a variable).
Javascript Date object and setInterval (to write out the clock) would make short work of this.
- dbloc0
I know I thought about the clock being wrong problem. How hard is the server side thing?
- dbloc0
or can I grab from an online clock somewhere?
- monNom0
if you want to rebase your client's clock to the server clock, pass the server time into a javascript variable, subtract from the time returned by a new Date() object, then add (subtract?) that to the time each time you create a new date object..
ie:
var serverTime = 123456;
var clientTime = new Date();
var rebase = clientTime-serverTime;
var WhatTimeIsItReally = new Date() + rebase;
- dbloc0
actually this was best JS based on users clock
http://praveenlobo.com/techblog/…count up and count down versions