tags:

views:

40

answers:

3

Pretty much as the question says, I have some code running on an interval:

$("#blah").fadeOut(2000);
$("#blah2").fadeIn(2000);

I'd like to fadeOut, then fadeIn, rather than have both going simultaneously. Is there an easy way?

+1  A: 

You need to make use of the callback functionality to ensure, that the animation completes before calling another. Looks like:

$('#blah').fadeOut(2000, function(){
    $('#blah2').fadeIn(2000);
});

see. .fadeOut()

jAndy
+1  A: 
$('#blah').fadeOut(2000, function(){
    $("#blah2").fadeIn(2000);
});

As explained in the documentation:

.fadeOut( [ duration ], [ callback ] )

duration: A string or number determining how long the animation will run.

callback: A function to call once the animation is complete.

marcgg
+3  A: 
$("#blah").fadeOut(2000);
$("#blah2").delay(2000).fadeIn(2000);

Or:

$("#blah").fadeOut(2000, function(){
    $("#blah2").fadeIn(2000);
});
J-P
Perfect, thanks!
SLC