Exhaust bloc with top notices
-
I'm trying to implement a fixed bloc of notifications over the entire length of the site, which is located upwards and shows for a few seconds.
Here's the code:
function alert(text) { t = Date.now(); $('body').append('<div class="my-alert animate__animated animate__fadeInDown" id="'+t+'">' + text + '</div>');
setTimeout(function() { $('#' + t).addClass('animate__fadeOutUp'); }, 4000);
}
There is, however, a problem if we call a notice before the previous concealment, the previous will not be hidden, although it will have a timer visit in four seconds. What's the problem?
-
Because you have
t
- global variable.function alert(text) { const t = $('<div class="my-alert animate__animated animate__fadeInDown">' + text + '</div>'); $('body').append(t);
setTimeout(function() { t.addClass('animate__fadeOutUp'); }, 4000);
}