Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery FadeOut many divs at once

I am trying to fade out multiple divs at once and fade in one div after that completes. Here's the code:

if($(this).attr("id")==="benefits-button"){

    $("#solar-about, #home-page, #process-page, #financing-page, #vendors-page, #consump-info-page, #smart-page, #wind-page, #about-page").fadeOut(750, function() {
         $("#benefits-page").fadeIn(750);
    });
    }

When there are multiple divs in the selector, the fadeOut and fadeIn happen at the same time.

Question: How do I get the fadeIn after the fadeOut?

Thank you

like image 754
Vinny Avatar asked Apr 22 '12 23:04

Vinny


1 Answers

$("#benefits-page").fadeIn(750);

is working immediately because it's starting to work when the first element (#solar-about in your example) fadeOut animation is completed.

If you want to wait until all animations are completed than you can use .promise(), like this:

$("#solar-about, #home-page, #process-page, #financing-page, #vendors-page, #consump-info-page, #smart-page, #wind-page, #about-page").fadeOut(750).promise().done(function() {
     $("#benefits-page").fadeIn(750);
});

DEMO

like image 105
Okan Kocyigit Avatar answered Sep 24 '22 04:09

Okan Kocyigit