Google Groups Home
Help | Sign in
Message from discussion Looping animate function
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
ScottBruin  
View profile
 More options May 16, 9:23 pm
From: ScottBruin <sahulb...@gmail.com>
Date: Fri, 16 May 2008 18:23:46 -0700 (PDT)
Local: Fri, May 16 2008 9:23 pm
Subject: Looping animate function
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 to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google