PDA

View Full Version : jQuery: wait for an animation to finish



pskl
30 Oct 2010, 05:56 AM
Hi !
I'm still working on my gallery, and after a few hours of coding it's finally ready.
Just a little bug I'd like to correct, but I don't know how !

On psaikali.com, there's is a 'galeria' in the middle of the page. When the user clicks on the left/right arrow, it slides to show other artworks. So far, it's working.
The only thing I'd like to fix is when you click twice (or more) on the arrow, the sliding effect will happen twice.

But in my script, there are some conditionals existing to determine how long the sliding effect should be, depending on the number of artworks left to see. On a double click, these conditionals happen just once, so the expected result is destroyed

I'd like to know if there is some kind of jQuery (or javascript) code to put in my onclick function to tell : 'wait before the animation is finished, then do what you have to do'.

By the way, here is the line of my code doing the animation :

$("#galeria-slider").animate({ marginLeft:"+=1000px"}, 800 );

I hope I'm clear enough ! If some developpers around there have a trick to avoid this, it would be great !

Tchau.

Pierre

rodc
02 Nov 2010, 02:20 AM
Hey pskl ,
I'm not an expert on Jquery but I think this might be usefull for you .

http://stackoverflow.com/questions/461912/jquery-finish-one-animation-then-start-the-other-one

From what I understand Is that once the animation 1 is finished you would like to call something else . Aparently this can be acomplished using the callback function inside any jquery efect ,

you can do something like this :

$("#element1").slideUp(
"slow",
function(){
$("#element2").slideDown("slow");
}
);


the function inside the slideUp event is triggered once the animation is finished .

I hope this is somehow helpfull to you ,
cheers ,
rodc