jQuery fade in only when value has changed
I want #recentTrack to fade out and in, but only when the value for it has changed. At the moment it fades out and in every time the setInterval function is called:
$.getJSON('cache/lastfmCache.json', function(data){
$("#recentTrack").html(data.recenttracks.track[0].artist["#text"]);
});
$.get('update.php');
se开发者_如何学编程tInterval(function() {
$.ajax({url:'cache/lastfmCache.json', dataType:'json',timeout: 5000, success:function(data){
//if((data.recenttracks.track[0].artist["#text"]) == null) { $.get('update.php'); }
var x = data.recenttracks.track[0].artist["#text"];
var y = $("#recentTrack").html();
if(x != y) {
$("#recentTrack").fadeOut('slow',function(){ $(this).html(x).fadeIn("slow"); });
}
$.get('update.php');}
});
}, 10000);
Turns out it was adding a link to the #recentTrack h3. Fixed now.
精彩评论