2011-01-12 184 views
4

如何讓jQuery淡出$(「#recentTrack」),替換它的內容,然後再次淡入?當前的代碼淡出出來,並保持它隱藏,而不是再逐漸把它:jQuery淡入淡出

setInterval(
    function() 
    { 
      $.getJSON('cache/lastfmCache.json', function(data){ 
      var x = data.recenttracks.track[0].artist["#text"]; 
      var y = $("#recentTrack").html(); 
      if(x != y) { 
       $("#recentTrack").fadeOut('slow').html(x).fadeIn('slow)'; 
      }  
     $.get('update.php');  
    }); 
    }, 15000); 
+3

你是否知道你在fadeIn('slow')中有錯誤; ?它應該是fadeIn('slow'); – AJJ 2011-01-12 12:04:36

+1

`$(「#recentTrack」)。fadeOut('slow')。html(x).fadeIn('slow)';`這不會給你任何錯誤? – naiquevin 2011-01-12 12:05:48

回答

6

只要改變$("#recentTrack").fadeOut('slow').html(x).fadeIn('slow)';

到:

$("#recentTrack").fadeOut('slow', function(){ 
    $(this).html(x).fadeIn("slow"); 
}); 

這樣,你等待事件完成。