This function need little more work
Main Topics
Browse All TopicsMy JS is attached below, both rollUp and rollDown are complex functions that control some UI elements on my page. However I don't want rollDown to run until rollUp has finished. At the moment they are both run at the same time.
I might be getting confused but i though this was called Callback, how can i rewrite this so that rollDown won't run until rollUp is finished. I'm trying to do this without modifying the functions themselves. Is this possible, if not what would I need to add.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
it sounds like that the most efficient way you could do this is either to modify your rollUp() function to have it call rollDown() itself after it completes. other than that, you can probably use rollUp()'s return value (if it has one).
(code snippet)
only problem is, if rollUp() fails and never returns true, then you're in for some hefty waiting. :p
I'd use a similar approach to what NahThenLad suggested. Using a value under 100 for the second argument should make the function run right after rollUp returns.
> I might be getting confused but i though this was called Callback
You've got an event listener function there. A "callback" is a function passed to another function to be called once the function has finished running. I suppose it's a similar concept, but there is a difference.
> only problem is, if rollUp() fails and never returns true, then you're in for some hefty waiting.
The while loop will only ever be reached after the rollUp function returns.
@kravimir ~ i meant, if it returns false :p and if it doesn't return at all, then it's either a long wait or the script fails to complete successfully anyway.
---
and what I think alex wants done is a smooth transition between the rollUp and the rollDown. like *whoosh* tab goes up, then *whoosh* tab goes down. a setTimeout may do the trick, but it'll be really awkward-looking. :(
> i meant, if it returns false :p and if it doesn't return at all, then it's either a long wait or
> the script fails to complete successfully anyway.
Yes. My point is that I don't see a point to what you were suggesting.
> a setTimeout may do the trick, but it'll be really awkward-looking. :(
Well, yeah, if you use too long of a delay.
well, it seems awkward to me as well, truth be told. but alex mentioned that the two functions (rollUp and rollDown) ran at the same time... meaning that while rollUp() was still executing, rollDown was already called as well. meaning rollDown was running prior to rollUp returning.
now don't ask me why that happens :p prolly something within the rollUp / rollDown functions?
but (just humor me here :p), if it *does* cascade to rollDown even before the rollUp was returning, then the whole point of the exercise is to delay the rollDown call with just enough time to coincide with rollUp finishing.
you're right about it being awkward with a delay that's too long. but it'd also be awkward with a delay that's too short. there can be no delay exactly correct than a delay exactly as long as it takes the rollUp function to finish. :(
and a setTimeout call, with a constant delay, will always be second to a true solution that's dynamic. :( not only is the exact execution time not known, but it would also differ across browsers and systems.
i'm not saying mine is exactly right though. i mean, for what we know, rollUp may have a setTimeout of its own, and returns before everything that its supposed to do is done, and my solution would be invalid. but i'm just playing along with what alex stated his situation seemed like.
^ thinking back on that, it does sound like rollUp may have a time-delay function of its own in its content. meaning that there might not be an exact way to determine when it finishes, but to modify the rollUp function completely. :(
no way should it return prematurely except when it's explicitly set something to work over a period of time. :(
Business Accounts
Answer for Membership
by: NahThenLadPosted on 2009-09-27 at 15:58:56ID: 25435848
Hi Alex,
'), 1000);
I'm sure there is a better way to do this (I am not an expert with JS), but a possible solution (hack!) would be to use:
setTimeout(rollDown('#tab2
This would delay the rollDown function call for the time value set as the second argument (in ms). I would need to read up a bit on the jQuery callback mechanism to comment on that, though there are a few JS guru's here and one of them should be able to provide a more elegant solution.
All the best.