I am trying to create a toast message using jQuery.
When the "show" class is appended to the div, I want the toast message to fade in and then fade out after a few seconds.
Once the fade-out animation is complete, I need to remove the "show" class.
This is my first attempt at writing this code.
var showToast = function(msg) {
clearTimeout(window.timeoutToast);
$("toastDiv p").html(msg);
$("toastDiv").addClass("show");
window.timeoutToast = setTimeout(function() {
$("toastDiv").removeClass("show")
}, 3000);
};
I have tried calling clearTimeoutFunc and removing the show class.
However, if I click multiple times quickly, the toast message fades out and then immediately reappears.
I also attempted to use $("toastDiv").on("animationed webkitAnimationEnd oAnimationEnd MSAnimationEnd", function() { ... }) but the function was triggered when the fade-in animation finished.
Here is my HTML code:
<div class="toastDiv">
<p class="txt_toast">blablabla</p>
</div>
And here is my CSS:
.toastDiv.show{
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
Please help me fix my code...