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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Delay Question

Status
Not open for further replies.

korax

ISP
Oct 16, 2000
1
0
0
US
I have a shake browser script I am going to use, but I would like to delay the script by a few(?) seconds. Here is my script. Thanks for any help :)

<head>
<title>Earth Quake</title>
<script language=&quot;JavaScript&quot;>
function earthquake()
{

for (i=30;i>=10;i--)
{
window.moveBy(10,10);
window.moveBy(-10,0);
window.moveBy(0,-10);
}

for (i=10;i>=1;i--)
{
window.moveBy(i,i);
window.moveBy(-i,0);
window.moveBy(0,-i);
}

}
</script>
<body onload=&quot;earthquake()&quot;>
</body>
</head>
</html> [sig][/sig]
 
Try setTimeout(code, delay)
code - code to be executed
delay - time in milliseconds before code is executed

like following:

<HTML>

<head>
<title>Earth Quake</title>
<script language=&quot;JavaScript&quot;>
function earthquake()
{

for (i=30;i>=10;i--)
{
window.moveBy(10,10);
window.moveBy(-10,0);
window.moveBy(0,-10);
}

for (i=10;i>=1;i--)
{
window.moveBy(i,i);
window.moveBy(-i,0);
window.moveBy(0,-i);
}

}
</script>
<body onload=&quot;setTimeout('earthquake()',1000)&quot;>
</body>
</head>
</html>

[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top