[英]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. 我希望#recentTrack淡入淡出,但仅当其值已更改时才可以。 At the moment it fades out and in every time the setInterval function is called:
此刻它逐渐消失,每次调用setInterval函数时:
$.getJSON('cache/lastfmCache.json', function(data){
$("#recentTrack").html(data.recenttracks.track[0].artist["#text"]);
});
$.get('update.php');
setInterval(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. 事实证明,这是添加到#recentTrack h3的链接。 Fixed now.
立即修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.