Hi group,

I've been struggling with this problem for a day or two.

Situation:
- I want to have text slide back and forth across the browser at a
rate I set; I'm attempting to use animate to do this, and it works
pretty well (though seems very resource intensive). Basically, I take
the following steps: calculate width of element, parent element, and
the css left property. From there, decide which direction to go (left
or right, basically) and based on that decide what the target left:
##px should be. After computing these numbers, send the new offset to
animate and how long it should take to run (calculated based on width
and what rate of px/ms I want).

I've gotten code to work successfully for all the above. My struggle
comes up when trying to get this function to run over and over again
when the animate function has completed.

Solutions I've attempted:
- I've used setInterval('slider_master(),100)  to run another function
that only runs the above function (let's call it slider() ) if
slider() is not running. It sees if slider() is running because
slider() sets a variable true when it starts, false when it finishes.
This worked pretty well, but doesn't seem ideal as setInterval will
run forever.
- A while loop; my (well-versed cs major) friend suggested this.
Problem, it seems, is that animate does not "return" when it's done or
not so the loop constantly runs and slams the browser. He suggested I
use a wait function inside the while loop, but this does not exist in
Javascript.
- calling slider() in the callback of animate(). This works, but this
needs to run for a while (it's for a display kiosk) but my friend
there may be a stack overflow if I use this method for too long.

So, as you can see, solution A works but I'm not completely satisfied.
Is there anything I can do that would be better? Is there some sort of
pause/wait/delay function I could use in a while loop? Or am I
approaching this in the wrong way? Javascript's ideal ways of doing
things still elude me.

Thanks for any help,
Scott

Reply via email to