2012-04-26 19 views
0

は、それを編集すること自由に感じ、jqueryのフェードイン/アウトエルその後、フェードイン/アウトの新しいエル

とにかくこれは私がを取得しようとしているこれまでのところ

$('#foo').click(function() { 

    $('#foo2').html('<h4>Please wait...</h4>').fadeOut('fast'); 

    var sful = $('#foo3').fadeIn('fast').html('<h4>Success!</h4>').fadeOut('slow'); 
    setTimeout(sful, 4000); 

}); 

私が持っているコードです。 #foo2をクリックしてfadeInすると、fadeOutと#foo3(var sful)に続いてfadeIn/Outが実行されます。

答えて

0
$('#foo2') 
      .html('<h4>Please wait...</h4>') 
      .fadeOut('fast', function() { // callback start after fadeOut() 
          setTimeout(function() { 
           $('#foo3') 
             .fadeIn('fast') 
             .html('<h4>Success!</h4>') 
             .fadeOut('slow'); 
           }, 4000); 
          }); 
+0

あなたが唯一の失敗する可能性があります1つの期間引数を、必要があります。あなたのコードになります'.fadeOut([duration] [、callback])'の代わりに '.fadeOut([duration] [、easing] [、callback])'のようになります。 – freshnode

1
$('#foo2').html('<h4>Please wait...</h4>').fadeOut('fast', function() { 
    var sful = $('#foo3').fadeIn('fast').html('<h4>Success!</h4>').fadeOut('slow'); 
    setTimeout(sful, 4000); 
}); 

コールバック(アニメーションが終了した後function() { ..が実行されます。)http://api.jquery.com/fadeOut/(特に[,callback]セクションを参照してください。

関連する問題