Re: time delays anyone?

by "John Murray" <jmnc(at)lis.net.au>

 Date:  Thu, 5 Oct 2000 20:12:19 +1000
 To:  "Christopher Higgs" <c.higgs(at)landfood.unimelb.edu.au>
 Cc:  <hwg-techniques(at)mail.hwg.org>
 References:  edu
  todo: View Thread, Original
Building a news scroller from scratch. I ended up with what follows. It's a
bit verbose, but I want to leave it raw until I cross browser ready it [MSIE
5 I built it on] and play with stuff around it.

Along the way I had problems getting a handle on setTimeout()'s behaviour.
It was as though in some circumstances using more that one setTimeout()
created seperate instances of the function, and that sometimes it wrote over
the paramaters provided to the previous setTimeout.

I'm happy with what I have. But I'm now looking for a delay before the news
scrolling function commences. At the moment it starts immediately onLoad.

I tried creating a new date object, then running a loop inside an if
statement that created a second date object and compared the seconds elapsed
between the two ... when it is greater than 4 secs ... terminate the loop
... and the function flowed on to initiating the scroller.

It just wasn't robust enough.

So I guess I'm looking for sugestions for an up front delay before
initiating the scrolling loop which uses the setTimeout() functions. And I'm
after any experiences people have had with setTimout() and how people see it
behaving when used several times within one script. Any rules formal or
informal.

For example, if you place a setTimeout() within a while loop, the loop seems
to iterate through the setTimeout()'s and schedule there actions outside
independent of where your program flow may be up to. But if you call a
function using the expression slot in the setTimout() function it does stop
until the

I suppose in summary, I'd like to use setTimout() and it's related functions
as there dosn't seem an inbuilt pause() function, but I'm feeling shaky
about it's dependability with my methology, and I'm looking for the
definitive principles that underpin it's use.

This pausing stuff seems suprisingly finicky, at least with the methods I've
used, for something so fundamental to what a programmer would want to
implement.

<html>
<head>

<style type = "text/css">

.headlines {
text-decoration:none;
color:#000000;
font-size:10px;
font-weight:bold;
font-style:normal;
font-family:Arial, sans-serif;
}


#div4 {
position: absolute;
left: 200px;
top: 80px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
clip:rect(0,400,100,0);
}

#blocknews {
position: absolute;
left: 0px;
top: 0px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
}

#news1 {
position: absolute;
left: 0px;
top: 0px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news2 {
position: absolute;
left: 0px;
top: 100px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news3 {
position: absolute;
left: 0px;
top: 200px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news4 {
position: absolute;
left: 0px;
top: 300px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news5 {
position: absolute;
left: 0px;
top: 400px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news6 {
position: absolute;
left: 0px;
top: 500px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news7 {
position: absolute;
left: 0px;
top: 600px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news8 {
position: absolute;
left: 0px;
top: 700px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news9 {
position: absolute;
left: 0px;
top: 800px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

#news10 {
position: absolute;
left: 0px;
top: 900px;
width: 400px;
height: 100px;
z-index: 2;
background-color:#ffffff;
padding: 5px;
}

</style>

<script type = "text/javascript">

var newsNow = 0;
var posNow = 0;
var posStop = 0;
var timeoutMB;
var timeoutIN;
var browser;

function incrementNews(){

 if (newsNow < 9)


  posStop = posStop - 100;
  // clearTimeout(timeoutMB);
  moveBlock();
  newsNow = newsNow + 1;
  timeoutIN = setTimeout("incrementNews();",10000);

 }
 else {

  initiateNews();
 }
}

function moveBlock(){

 if (posNow > posStop)
 {
  posNow = posNow - 10;
  if (browser = 'IE4'){blocknews.style.top = posNow+'px';}
  timeoutMB = setTimeout('moveBlock();',100);
 }

}

function initiateNews(){
 newsNow = 0;
 posNow = 0;
 posStop = 0;
 incrementNews();
 }

function initiateStuff(){
 if (document.all){browser = 'IE4';}
 if (document.layers){browser = 'NN4';}
 initiateNews();
}

</script>

</head>

<body onLoad="initiateStuff();">

<div id = "div4">

 <div id="blocknews">
  <div id = "news1" class="headlines">
  &nbsp;
  </div>
  <div id = "news2" class="headlines">
Headline 1.
  </div>
  <div id = "news3" class="headlines">
Headline 2
  </div>
  <div id = "news4" class="headlines">
Headline 3
  </div>
  <div id = "news5" class="headlines">
Headline 4
  </div>
  <div id = "news6" class="headlines">
Headline 5
  </div>
  <div id = "news7" class="headlines">
Headline 6
  </div>
  <div id = "news8" class="headlines">
Headline 7
  </div>
  <div id = "news9" class="headlines">
Headline 8
  </div>
  <div id = "news10" class="headlines">
  WHATS MAKING NEWS FOLLOWS ...
  </div>
 </div>

</div>

</body>
</html>


----- Original Message -----
From: Christopher Higgs <c.higgs(at)landfood.unimelb.edu.au>
To: John Murray <jmnc(at)lis.net.au>; <hwg-techniques(at)mail.hwg.org>
Sent: Thursday, October 05, 2000 4:58 PM
Subject: Re: time delays anyone?


> At 13:37 5/10/00 +1000, John Murray wrote:
> >Anyone want to talk setTimeout() and how to effectly manage pausing your
> >scripts?
>
> What sort of pause are you trying to achieve?
>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA