views:

1158

answers:

2

Hi guys, I know this is a simple one for some of you, so please help me out! I have 3 panels (divs) which I want to slide one after the other from clicking a button. Sliding one panel is easy but how to slide multiple divs in order? Thanks.

+6  A: 
Kane Wallmann
+100, Excellent use of arguments.callee! Here's the working demo page. http://jsbin.com/utebe I thought this might help the author understand how the DIVs are to be structured.
SolutionYogi
I edited your post to add the link to demo page, I hope you don't mind.
SolutionYogi
I would only write the if condition a little differently. if(++i < arr.length)
SolutionYogi
That's one of the coolest trick of JS I've ever heard!
xandy
That is pretty clever.
seth
A: 
SolutionYogi
You guys are awesome. 30 minutes and look what already has been done! Anyhoo, you're right, I don't understand anonymous functions etc. By looking at your code however, I guess that the length of the list determines when to start animating the next div? What if I wanted to slide the divs horizontally, right-to-left?
lorenzium
length of list determines whether one needs to sequence another animation. E.g. above code will work, if you add 4th div with class 'slide'. It will animate the 4th div, after the 3rd one has finished animating. And if you want different animation, change 'slideUp' method with relevant method. Let me edit the code to show you how.
SolutionYogi
I added a bit of CSS to http://jsbin.com/adaca/edit // makes it a bit clearer...
lorenzium
I updated the main answer to link to your demo page and some comments.
SolutionYogi
When you said 'Let me edit the code to show you how', was that to show me how it would be done horizontally? I don't see any changes in the demo except that the css has been added...
lorenzium
See http://stackoverflow.com/revisions/1169464/list to know how you can modify the code to suit your purpose. I didn't modify the demo.
SolutionYogi
Thanks Yogi, finally got it!
lorenzium