Re: setTimeout only delays first time in loop
- From: barry@xxxxxxxxxxxxxx
- Date: 13 Sep 2006 10:29:22 -0700
Thanks guys. I incremented the delay for each iteration and it worked.
Jim Davis wrote:
The key is going to be how you're calling that timeout. My guess is you've
put it in a loop and set 20 timeouts - think about it: of course they'd all
move at the same time (or very close) since you're setting them all at once.
;^)
I'm not sure I understand how the script is executed for it to work the
way it does. The way I figured, my original timeout said "delay 700ms,
then execute the named function (funtest)," then after funtest is
executed (which changes the position of a single li element), the
statement after the timeout is executed, which is within the same loop
of the timeout, and the loop would cause the timeout to be executed
again, causing another 700ms delay before another li changes position.
But as far as I could tell, you're saying that Javascript sees the
delay the first time, delays 700ms, then thinks "ok, I delayed 700ms
before funtest, and even if I encounter the 700ms timeout 19 more
times, that job was done so I don't have to delay again, but I still
have to execute funtest each time."
Anyone know of any online documentation for setTimeout that makes it
clear that the latter is the way it works rather than the former, or is
there a problem with my logic?
.
- Follow-Ups:
- Re: setTimeout only delays first time in loop
- From: Dr John Stockton
- Re: setTimeout only delays first time in loop
- References:
- setTimeout only delays first time in loop
- From: barry
- Re: setTimeout only delays first time in loop
- From: Jim Davis
- setTimeout only delays first time in loop
- Prev by Date: based64 decoding in javascript
- Next by Date: Re: setTimeout only delays first time in loop
- Previous by thread: Re: setTimeout only delays first time in loop
- Next by thread: Re: setTimeout only delays first time in loop
- Index(es):
Relevant Pages
|