Employing metronome timers .........................................................
To create a page where something repeats at intervals, you use the same
timer object but in a slightly different way. In the previous two timer examples,
you used the setTimoutcommand to cause a delay, and then activated some
behavior. If you want repeating behavior, you need a metronome type of timer.
It’s created by using the setIntervalcommand, like this:
timerhandle = setInterval (“movep”,200)
The difference between setTimeoutand setIntervalis that with
setInterval, the function (movep, in this next example) is executed
repeatedly instead of executed only once. Here’s an example.
<html>
<head>
<script LANGUAGE=”VBScript”>
dim toggle
function startTimer()
timerhandle = setInterval(“movep”,100)
end function
function stopTimer()
clearTimeout(timerhandle)
end function
function movep()
toggle = not toggle
if toggle then
para.style.color = “slateblue”
else
para.style.color = “black”
end if
end function
</script>
</head>
<body onload=”startTimer()” onunload=”stopTimer()”>
<p ID=”para” style=”font-size: 24px;”>This text vibrates a
little bit!</p>
</body>
</html>
294 Part IV: Advanced CSS Techniques