6

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

Vinny
  • 309
  • 3
  • 11

1 Answers1

17
$("#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

Lionel
  • 1,949
  • 3
  • 17
  • 27
Okan Kocyigit
  • 13,203
  • 18
  • 70
  • 129