[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

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=pageYOffset
else if (document.all)
{
test.innerHTML='<div align=center><font face="Verdana">'+themessage+'</font></div>'
setTimeout("test.style.top=document.body.scrollTop+10;test.style.left=document.body.scrollLeft+10",100)
}
else if (document.getElementById){
document.getElementById("test").innerHTML='<div align=center><font face="Verdana">'+themessage+'</font></div>'
document.getElementById("test").style.top=pageYOffset
}
}

function expand()
{
if (document.layers){
document.test.document.write('<div align=center style="font-size:'+fontsize+'px"><font face="Verdana">'+themessage+'</font></div>')
document.test.document.close()
}
else if (document.all)
test.style.fontSize=fontsize+'px'
else if (document.getElementById)
document.getElementById("test").style.fontSize=fontsize+'px'
fontsize+=5
if (fontsize>90){
if (document.layers)
setTimeout("document.test.visibility='hide'",appearfor)
else if (document.all)
setTimeout("test.style.visibility='hidden'",appearfor)
else if (document.getElementById)
setTimeout("document.getElementById('test').style.visibility='hidden'",appearfor)
return
}
else
setTimeout("expand()",50)
}

</script>

<script>
//I need this script to be delayed 1700 miliseconds

var size = 25;
var speed_between_messages=1500 //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('idee').innerHTML = 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;font-weight:bold; margin:0000; color:#FF9900;" id="test"></div>
<div style="position:absolute;font-weight:bold; margin:0000; font-family: Verdana; font-size:12pt;COLOR:#6C6C6C;" ID="idee"></div>


</body>
</html>
0
dmullis
Asked:
dmullis
  • 2
  • 2
1 Solution
 
GuicCommented:
hi,

Put your  script to be delayed 1700 miliseconds in a function called for example "yourFunctionToDelayed()"


function yourFunctionToDelayed() {
     // what you want ...
}
window.setTimeout("yourFunctionToDelayed()",1700);

Regards
0
 
dmullisAuthor Commented:
Hi Guic,

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("startmotor(3000)",1700);
}
</script>



This is the call to all the functions in the body onload:

<body onload="position_at_top();expand();startmotor(3000)"/>


<div style="position:absolute;font-weight:bold; margin:0000; color:#FF9900;" id="test"></div>
<div style="position:absolute;font-weight:bold; margin:0000; font-family: Verdana; font-size:12pt;COLOR:#6C6C6C;" ID="idee"></div>
0
 
dmullisAuthor Commented:
Guic,

I got it! Thanks!

<body onload="position_at_top();expand();window.setTimeout('startmotor(3000)',3000);"/>
0
 
GuicCommented:
right ! =)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now