18
jQuery(document).ready(function(){
    $(".welcome").fadeOut(9500);
    $(".freelance").fadeIn(10000);
    $(".freelance").fadeOut(4500);
});

I want the welcome message to fadeOut slowly and then the other div to fadeIn its place and then fadeOut - obviously when the welcome box no longer exists.

<header>
    <h1 class="left"><a href="index.html"></a></h1>
    <div class="left yellowbox welcome"><p>Welcome to my portfolio.</p></div>
    <div class="left greenbox freelance"><p>I am currently available for for work, contact me below.</p></div>
</header>
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209

4 Answers4

31

You need to call the additional fadeIn() and fadeOut inside of a callback function to the first one. All animation methods (and many others) in jQuery allow for callbacks:

jQuery(document).ready(function(){
    $(".welcome").fadeOut(9500,function(){
        $(".freelance").fadeIn(10000, function(){
            $(".freelance").fadeOut(4500);
        });
    });
});

This will cause .welcome to fade out first. Once it's done fading out, .freelance will fade in. Once it's done fading in, it will then fade out.

maxedison
  • 17,243
  • 14
  • 67
  • 114
  • I got it working by hiding it first using your code: jQuery(document).ready(function(){ $(".freelance").hide(); $(".welcome").fadeOut(6500,function(){ $(".freelance").fadeIn(2500, function(){ $(".freelance").fadeOut(4500); }); }); }); – TheBlackBenzKid Sep 24 '11 at 15:00
  • I did that too so that it does not hide on the page load. Using .hide can make it appear during load and then disappear after load which makes a bad UX – TheBlackBenzKid Sep 26 '11 at 09:28
1
jQuery(document).ready(function(){
   $(".welcome").fadeOut(9500, function() {
      $(".freelance").fadeIn(500, function () {
          $(".freelance").fadeOut(4500);
      });
   });
});
Joakim
  • 2,217
  • 15
  • 20
  • almost right, except you need the fadeOut of .freelance to be in the callback of the fadeIn call on .freelance. Your current code is both fading .freelance in and out at the exact same time. – maxedison Sep 24 '11 at 13:13
  • @maxedison thank you, it still works the way it was meant tho, edited my answer anyway. – Joakim Sep 24 '11 at 13:15
0

I believe that this code might work

$(".welcome").fadeOut(9500).queue(function(next) { 
    $(".freelance").fadeIn(10000).queue(function(next) {
        $(".freelance").fadeOut(4500);
    });
});         
jwchang
  • 10,584
  • 15
  • 58
  • 89
0

You probably want .delay()

jQuery(document).ready(function(){
    $(".welcome").delay(9000).fadeOut(9500);
    $(".freelance").delay(10000).fadeIn(10000);
    $(".freelance").delay(145000).fadeOut(4500);
});
genesis
  • 50,477
  • 20
  • 96
  • 125