Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help me with a countdown script

Help me with a countdown script
Thread Tools
Ozmodiar
Mac Elite
Join Date: Apr 2002
Location: Quetzlzacatenango
Status: Offline
Reply With Quote
Aug 8, 2004, 01:55 AM
 
Hey boys and girls,

I want to put a timer on a page I coded that will count down to the day of the US Federal Elections (November 2, 2004). I think it would be cool to have it precise down to the millisecond, much like the Flash counter that Apple had on its page counting down to the release of the PowerMac G5.

Does anyone know a good script/applet that can do this? If it needs to be done in Flash (for aesthetic purposes) then I might be up a creak, but it's worth a shot.

Thanks,
Oz
     
madmacgames
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Aug 8, 2004, 11:50 AM
 
just a quick google search turned up these (hey why reinvent the wheel, eh?):

http://www.dynamicdrive.com/dynamici...dhtmlcount.htm
http://www.dynamicdrive.com/dynamici...htmlcount2.htm

I'm sure there are many others, but I don't feel like searching google all day for you
     
Ozmodiar  (op)
Mac Elite
Join Date: Apr 2002
Location: Quetzlzacatenango
Status: Offline
Reply With Quote
Aug 8, 2004, 06:09 PM
 
Thanks for the reply. This is a cool script, but I'm wondering if it's possible to edit it so that it counts down to the millisecond. Do you know what I could add to the script to make it do so?
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Aug 8, 2004, 11:12 PM
 
Originally posted by Ozmodiar:
Thanks for the reply. This is a cool script, but I'm wondering if it's possible to edit it so that it counts down to the millisecond. Do you know what I could add to the script to make it do so?
The browser CPU load required to display that kind of update would be bad. I did a simple test counting down from 1000 to 0 over and over (setInterval of 1 ms) and it pegs the CPU in my 900Mhz G3 and still takes longer than 1ms per update.

Here's some code you can play with:

[php]
<html>
<head>
<script language="JavaScript">
function showMilliseconds()
{
newmillivalue = document.forms[0].milliseconds.value -1;
if ( newmillivalue < 0 )
{
newmillivalue = 999;
document.forms[0].itercount.value = parseInt(document.forms[0].itercount.value) +1;
}
document.forms[0].milliseconds.value = newmillivalue;
}

</script>
</head>
<body onload="setInterval('showMilliseconds()', 1)">
<form>
Count: <input type="text" name="itercount" value="0">
<br/>
Milliseconds: <input type="text" name="milliseconds" value="0">
<br/>
</form>
</html>
[/php]
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
madmacgames
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Aug 9, 2004, 12:44 AM
 
I dunno if I would want to count to the millisecond in javascript. Would probably want to use flash or something of the sort for that.

Here is a tutorial on how to do it with flash, including milliseconds:
http://www.kirupa.com/developer/mx/countdown.htm
     
Ozmodiar  (op)
Mac Elite
Join Date: Apr 2002
Location: Quetzlzacatenango
Status: Offline
Reply With Quote
Aug 9, 2004, 02:17 AM
 
Thanks guys!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:22 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,