PDA

View Full Version : Delay


CowboyInMe
09-08-2004, 10:28 PM
How would one go about delaying a script for a split second, then carry out the next action, such as moving a picture down, pausing, then moving down again. A for loop just makes it go light speed :mad: I want it to take its time moving down the screen.

Thanks -Cowboy

WA
09-08-2004, 10:37 PM
You'll want to use setTimeout(). For example:

setTimeout("moveit()", 1000)

delays executing "moveit()" for 1 second. For more info, check out the methods section of Window: http://www.javascriptkit.com/jsref/window.shtml

Willy Duitt
09-08-2004, 10:44 PM
Use setTimeout()....

Below is an example... Albiet the image moves from side to side but the frog can not walk down without modification...


<script type="text/javascript">
<!--//
var left = -100;
function moveIt(){
if (left <= window.screen.availWidth){
document.getElementById('theFrog').style.left = left + 'px';
move = setTimeout('moveIt(left+=4)',100);
}
if (left >= window.screen.availWidth){
clearTimeout(move);
left = -100;
moveIt();
}
}
//-->
</script>
</head>
<body onload="moveIt()">

<div style="position:absolute;over-flow:hidden">
<img id="theFrog" style="position:relative; top:0; left:-100px; z-index:2"
src="http://nunzioweb.com/misc/frogwalk.gif">
</div>


.....Willy

CowboyInMe
09-08-2004, 11:50 PM
hey thanks guys, i appreciate it. works great :)