JQuery Fade In and Out

How do I get jQuery to decrease the value of $ ("# recentTrack"), replace its contents, and then extinguish it again? The current code disappears and keeps it hidden, rather than fading out again:

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); 
+4
source share
1 answer

Just change $("#recentTrack").fadeOut('slow').html(x).fadeIn('slow)';

in

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

So you are waiting for the event to complete.

+6
source

Source: https://habr.com/ru/post/1335234/


All Articles