ciao
you cannot slow down a loop: loops are meant to be the faster the better.
use setInterval : see on a manual the documentation for it, should be under
the window object. I mean that now a full description of how setInterval
works printed right here would require maybe 15 minutes. I hope having
pointed to you the method will suffice.
Loops cannot be slow down, not in javaScript and not in other languages.
Also functions like sleep that a few languages have are not meant to make
loops slow, but to postpone the execution of blocks of codes - but that's
server side, like a flush() method say.
ciao
Alberto Vallini
ciao
uhm why not using both? I mean an old way of doing soemthing doesn't age:
the document.images collection is an useful tool: it grants you the option
to loop throughout ALL the available images with an array already arranged.
otherwise you'd have to arrange it yourself, either patching up a collection
by repeatedly calling in document.getElementById('image101') or by
document.getElementsByTagName("A")
the former is highly unpractical, the second is much slower than just using
an object which is already within the built in arrays of a loaded document.
It is not an issue of purist vs moderns: it is that I'm suggesting: use
both - dismissing the name just because they ADDED the id feature doesn't
mean you have to give up the possibility to scan all your images with an
alrerady available collection. Again, name= is NOT deprecated.
Of course, feel free to dismiss my suggestion, but please: it is NOT a
suggestion of "old school" vs "new school": it is the suggestion that
everybody with javascript expereince would be likely to lend to you.
Of course, eventually do as you prefer. yet using two weapons instead than
one is better - we have not given up the rifle because we have the scuds.
ciao
Alberto
http://www.unitedscripters.com/
"TheKeith" <no@spam.com> ha scritto nel messaggio
news:X9ydnegIgocSDQGiRVn-gA@giganews.com...[color=blue]
>
> "TheKeith" <no@spam.com> wrote in message
> news:6cadnZsur9jBGQGiRVn-sg@giganews.com...[color=green]
> > I'm writing a script with a while loop in it. How can I get it to go[/color]
> slower[color=green]
> > so that it doesn't appear to happen all at once--so that it looks
> > animated--basically. I tried the setTimeout(500) in the last line of the
> > loop, but that just messes things up. Any help would be[/color]
> appreciated--thanks.
>
>
> here is what I'm doing:
>
> <html>
> <head>
> <script type="text/JavaScript">
> function growbluebox(widthto,heightto) {
>
> var idofbluebox = document.getElementById("bluebox")
> var idofbluebox = document.getElementById("bluebox")
> var blueboxwidthnum = parseInt(idofbluebox.style.width)
> var blueboxheightnum = parseInt(idofbluebox.style.height)
>
> while (blueboxwidthnum < widthto) {
> blueboxwidthnum = parseInt(idofbluebox.style.width) + 1;
> idofbluebox.style.width = blueboxwidthnum + "px";
> }
>
> }
> </script>
> </head>
> <body>
> <a href="#" onClick="growbluebox(500,400)">grow by 200 wide and 200[/color]
high</a>[color=blue]
> <div id="bluebox" style="position:absolute; left:189px; top:96px;
> width:228px; height:129px; z-index:1; background-color: #99CCFF;
> layer-background-color: #99CCFF; border: 1px none #000000;"></div>
> </body>
> </html>
>
> I'm trying to have the box grow slowly so it looks animated. I didn't get
> around to the height part yet. BTW, is there a way I can do the height at
> the same time as the width? Thanks.
>
>[/color]