2011-01-12 196 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"); 
}); 

这样,你等待事件完成。