dmullis
asked on
Need second script to be delayed
Hi Experts, Gurus and Sages,
I am trying to learn JavaScript and have tried putting "setTimeout" all ove the place but the right one, I guess. I have 2 scripts. I want the second script (which is called by body onload like the first script) to be delayed - wait for the first script to almost finish before executing. Can you help? The enitire code is below- First and second scripts - you can save as htm and view as it is. Search for the comment: "//I need this script to be delayed 1700 miliseconds". This is the begining of the second script that I wish to be delayed.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript">
//This script created by Steve Bomer (steveb03@yahoo.com)
//Modified by Deidre Mullis
function start(){
position_at_top();
expand();
startmotor(3000);
}
//Change the message below
var themessage="FLASH!"
var fontsize=10
//Below determines how long the message will appear before disappearing. 3000=3 seconds
var appearfor=2000
function position_at_top()
{
if (document.layers)
document.test.top=pageYOff set
else if (document.all)
{
test.innerHTML='<div align=center><font face="Verdana">'+themessag e+'</font> </div>'
setTimeout("test.style.top =document. body.scrol lTop+10;te st.style.l eft=docume nt.body.sc rollLeft+1 0",100)
}
else if (document.getElementById){
document.getElementById("t est").inne rHTML='<di v align=center><font face="Verdana">'+themessag e+'</font> </div>'
document.getElementById("t est").styl e.top=page YOffset
}
}
function expand()
{
if (document.layers){
document.test.document.wri te('<div align=center style="font-size:'+fontsiz e+'px"><fo nt face="Verdana">'+themessag e+'</font> </div>')
document.test.document.clo se()
}
else if (document.all)
test.style.fontSize=fontsi ze+'px'
else if (document.getElementById)
document.getElementById("t est").styl e.fontSize =fontsize+ 'px'
fontsize+=5
if (fontsize>90){
if (document.layers)
setTimeout("document.test. visibility ='hide'",a ppearfor)
else if (document.all)
setTimeout("test.style.vis ibility='h idden'",ap pearfor)
else if (document.getElementById)
setTimeout("document.getEl ementById( 'test').st yle.visibi lity='hidd en'",appea rfor)
return
}
else
setTimeout("expand()",50)
}
</script>
<script>
//I need this script to be delayed 1700 miliseconds
var size = 25;
var speed_between_messages=150 0 //in miliseconds
var tekst = new Array()
{
tekst[0] = "Flash Website Builder";
//tekst[1] = "Here you can type anything you want";
//tekst[2] = "You can change the size";
//tekst[3] = "And you can change the speed";
}
var klaar = 0;
var s = 0;
var veran =0;
var tel = 0;
function bereken(i,Lengte)
{
return (size*Math.abs( Math.sin(i/(Lengte/3.14))) );
}
function motor(p)
{
var output = "";
for(w = 0;w < tekst[s].length - klaar+1; w++)
{
q = bereken(w/2 + p,16);
if (q > size - 0.5)
{klaar++;}
if (q < 5)
{tel++;
//
if (tel < 1)
{
tel = 0;
if (veran == 1)
{
veran = 0;
s++;
if ( s == tekst.length)
{s = 0;}
p = 0;
if (window.loop)
{clearInterval(loop)}
loop = motor();
}
}
}
output += "<font style='font-size: "+ q +"pt'>" +tekst[s].substring(w,w+1) + "</font>";
}
for(k=w;k<klaar+w;k++)
{
output += "<font style='font-size: " + size + "pt'>" +tekst[s].substring(k,k+1) + "</font>";
}
document.getElementById('i dee').inne rHTML = output;
}
function startmotor(p)
{
if (!document.getElementById)
return
var loop = motor(p);
if (window.time) {
var time = setTimeout("startmotor(" +(p+1) + ")", speed_between_messages);
} else {
var time =setTimeout("startmotor(" +(p+1) + ")",100);
}
}
</script>
</head>
<body onload="start()">
<div style="position:absolute;f ont-weight :bold; margin:0000; color:#FF9900;" id="test"></div>
<div style="position:absolute;f ont-weight :bold; margin:0000; font-family: Verdana; font-size:12pt;COLOR:#6C6C 6C;" ID="idee"></div>
</body>
</html>
I am trying to learn JavaScript and have tried putting "setTimeout" all ove the place but the right one, I guess. I have 2 scripts. I want the second script (which is called by body onload like the first script) to be delayed - wait for the first script to almost finish before executing. Can you help? The enitire code is below- First and second scripts - you can save as htm and view as it is. Search for the comment: "//I need this script to be delayed 1700 miliseconds". This is the begining of the second script that I wish to be delayed.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript">
//This script created by Steve Bomer (steveb03@yahoo.com)
//Modified by Deidre Mullis
function start(){
position_at_top();
expand();
startmotor(3000);
}
//Change the message below
var themessage="FLASH!"
var fontsize=10
//Below determines how long the message will appear before disappearing. 3000=3 seconds
var appearfor=2000
function position_at_top()
{
if (document.layers)
document.test.top=pageYOff
else if (document.all)
{
test.innerHTML='<div align=center><font face="Verdana">'+themessag
setTimeout("test.style.top
}
else if (document.getElementById){
document.getElementById("t
document.getElementById("t
}
}
function expand()
{
if (document.layers){
document.test.document.wri
document.test.document.clo
}
else if (document.all)
test.style.fontSize=fontsi
else if (document.getElementById)
document.getElementById("t
fontsize+=5
if (fontsize>90){
if (document.layers)
setTimeout("document.test.
else if (document.all)
setTimeout("test.style.vis
else if (document.getElementById)
setTimeout("document.getEl
return
}
else
setTimeout("expand()",50)
}
</script>
<script>
//I need this script to be delayed 1700 miliseconds
var size = 25;
var speed_between_messages=150
var tekst = new Array()
{
tekst[0] = "Flash Website Builder";
//tekst[1] = "Here you can type anything you want";
//tekst[2] = "You can change the size";
//tekst[3] = "And you can change the speed";
}
var klaar = 0;
var s = 0;
var veran =0;
var tel = 0;
function bereken(i,Lengte)
{
return (size*Math.abs( Math.sin(i/(Lengte/3.14)))
}
function motor(p)
{
var output = "";
for(w = 0;w < tekst[s].length - klaar+1; w++)
{
q = bereken(w/2 + p,16);
if (q > size - 0.5)
{klaar++;}
if (q < 5)
{tel++;
//
if (tel < 1)
{
tel = 0;
if (veran == 1)
{
veran = 0;
s++;
if ( s == tekst.length)
{s = 0;}
p = 0;
if (window.loop)
{clearInterval(loop)}
loop = motor();
}
}
}
output += "<font style='font-size: "+ q +"pt'>" +tekst[s].substring(w,w+1)
}
for(k=w;k<klaar+w;k++)
{
output += "<font style='font-size: " + size + "pt'>" +tekst[s].substring(k,k+1)
}
document.getElementById('i
}
function startmotor(p)
{
if (!document.getElementById)
return
var loop = motor(p);
if (window.time) {
var time = setTimeout("startmotor(" +(p+1) + ")", speed_between_messages);
} else {
var time =setTimeout("startmotor(" +(p+1) + ")",100);
}
}
</script>
</head>
<body onload="start()">
<div style="position:absolute;f
<div style="position:absolute;f
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Guic,
I got it! Thanks!
<body onload="position_at_top(); expand();w indow.setT imeout('st artmotor(3 000)',3000 );"/>
I got it! Thanks!
<body onload="position_at_top();
right ! =)
ASKER
This is the function I need to be delayed with the window.setTimeout included. This doesn't delay this function from starting? Do I have the setTimeout in the wrong place?
function startmotor(p)
{
if (!document.getElementById)
return
var loop = motor(p);
if (window.time) {
var time = setTimeout("startmotor(" +(p+1) + ")", speed_between_messages);
} else {
var time =setTimeout("startmotor(" +(p+1) + ")",100);
}
window.setTimeout("startmo
}
</script>
This is the call to all the functions in the body onload:
<body onload="position_at_top();
<div style="position:absolute;f
<div style="position:absolute;f