Search code examples
javascriptjqueryfadeinfadeout

JQuery fadeOut(function(){fadeIn});


I have a problem with my webpage. I have 4 div's which should all fade in after the one before fades out. The code I use is:

$('.btn').click(function(){
    $('#box3').delay(5000).fadeOut('slow', function(){
        $('#box4').fadeIn('slow');
    });
});

With #box1 > #box2 it works, with #box2 > #box3 it works but when I try to go from #box3 > #box4 sometimes #box3 fades out then fades in with #box4. I have No idea why it is doing this.

Thanks,

http://jsfiddle.net/chLRa/4/ now working. Sometimes when going from 3 to 4 it still fades in 3 and 4


Solution

  • Here's a simple helper function to help you do this.

    function fade(thisIn, callback){
        boxes.not(thisIn).filter(':visible').delay(5000).fadeOut('slow', function(){
            thisIn.fadeIn('slow', callback);
        });
    }
    

    jsFiddle