Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting an animation so it runs at certain times.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Please help me with A CS problem.
I need to set this up so the animation only runs when the alarm is on and the counter is showing a negitive number. Can anyone Help me?



<html>
<head>
<title>prog5T</title>
<script>
/*DEFINITIONS:
&quot;running&quot; starts &quot;false&quot; but is &quot;true&quot; after the timer has been started and remains &quot;true&quot; until a reset occurs
&quot;counting&quot; starts &quot;false&quot; and is toggled by the start stop button
&quot;dirup&quot; starts &quot;true&quot; and defines the direction up or down that the timer counts and is toggled up the direction button
&quot;init&quot; is the value from which the timer is set to start counting
&quot;alarm&quot; starts false but becomes &quot;true&quot; when &quot;count&quot; is negative and starts the twinkles anmation if &quot;alarmon&quot; is &quot;true&quot;
When alarmon is &quot;false&quot; the twinkles animation does not turn on when alarm=true
*/
function Start_Stop_Button()
{thetime=new Date();
counting=!counting;
if(running==false){start=thetime; running=true ;}else
{delt=thetime-start; document.myForm.Counter.value=&quot;Count=&quot;+(init+((dirup==true)?delt:-delt)/1000)+&quot;secs&quot;}
}
function Reset_Button()
{running=false;
init=+document.myForm.Initcount.value;//NOTE TYPE CONVERSION to try to get number
alarm=false; counting=false;
if (isNaN(init)){init=0; document.myForm.Initcount.value=&quot;Enter value of counter here (reset to zero as default)&quot;};
document.myForm.Counter.value=&quot;Count=&quot;+init+&quot;secs&quot;;
}
function Direction_Button()
{document.myForm.Direction.value=(dirup==false)?'Count Up':'Count Down';
dirup=!dirup;
}
function pclock()
{time=new Date();
document.myForm.Date_Time.value=time;
if(counting==true){count=init+(time-start)*((dirup==true)? 1:-1)/1000;
document.myForm.Counter.value=&quot;Count=&quot;+count+&quot;secs&quot;;
if(count<0) {alarm=true}else {alarm=false};}
setTimeout(&quot;pclock();&quot;,100);
}
}
function Alarmset_button()
{document.myForm.Alarmset.value=
/* Following function definitions variables are initialized
*/
running=false; counting=false ; dirup=true; init=0; alarmon=true; alarm=false;
</script>
</head>
<body text=&quot;#FFFFFF&quot; bgcolor=&quot;#000000&quot; onload=&quot;pclock();&quot;>
<!-- The following are the layer definitions for Gwen' twinkles -->
<LAYER NAME=&quot;a&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<LAYER NAME=&quot;b&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<LAYER NAME=&quot;c&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<LAYER NAME=&quot;d&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<LAYER NAME=&quot;e&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<LAYER NAME=&quot;f&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<LAYER NAME=&quot;g&quot; LEFT=10 TOP=10 VISIBILITY=SHOW BGCOLOR=&quot;#FFFF00&quot;
CLIP=&quot;0,0,15,15&quot;></LAYER>
<script LANGUAGE=&quot;JavaScript&quot; SRC=&quot;twinkleT.js&quot;></script>
<form NAME=&quot;myForm&quot;><input TYPE = &quot;text&quot; NAME = &quot;Date_Time&quot; SIZE = 60><font color=&quot;#FFFF00&quot;>
<font size=+1><a href=&quot; TARGET=&quot;GOV CLOCK&quot;>Click here for Official US Government Time</a>
</font></font><p>
<input TYPE = &quot;text&quot; NAME = &quot;Initcount&quot; Value= &quot;Enter value of counter here (reset to zero as default&quot; SIZE = 60>
<input TYPE=&quot;button&quot; NAME=&quot;Direction&quot; VALUE=&quot;Count Up &quot; onClick=&quot;Direction_Button()&quot;>
<input TYPE=&quot;button&quot; VALUE=&quot;Reset Count&quot; onClick=&quot;Reset_Button()&quot;>
<input TYPE = &quot;text&quot; NAME = &quot;Counter&quot; SIZE = 20>
<input TYPE=&quot;button&quot; VALUE=&quot;Start/Stop&quot; onClick=&quot;Start_Stop_Button()&quot;>
<input TYPE=&quot;button&quot; NAME=&quot;Alarmset&quot; VALUE=&quot; Alarm On &quot;
onClick=&quot;this.value=(alarmon==false)?' Alarm On':' Alarm Off';alarmon=!alarmon&quot;></form>
</body>
</html>
 
If I understand your question correctly, I think all you need to do is to change your 'pclock' function as shown in red below:-

function pclock() {
time=new Date();
document.myForm.Date_Time.value=time;
if(counting==true)
{
count=init+(time-start)*((dirup==true)? 1:-1)/1000;
document.myForm.Counter.value=&quot;Count=&quot;+count+&quot;secs&quot;;
if(count<0) {alarm=true}
else {alarm=false};
}

if (alarm && alarmon) { insert call to twinkle function here }
else { insert call to 'stop' function here }

setTimeout(&quot;pclock();&quot;,100);
}

HTH :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top