Utilizing the CSS and HTML code below to showcase a notification whenever an event takes place.
HTML
<div id="notification_wrapper">
<div id="notification"></div>
</div>
CSS
#notification_wrapper
{
position: fixed;
left: 50%;
float: left;
z-index: 1060;
}
#notification
{
left: -50%;
float: left;
position: relative;
border: solid 1px black;
padding: 10px;
border-radius: 5px;
box-shadow: 0px 0px 20px #000000;
background-color: yellow;
font-weight: bold;
display: none;
}
jQuery
$("#notification").text("A message tobe displayed").fadeIn().fadeOut(5000);
The current issue is that when I trigger the jQuery code with a button click, the notification displays correctly and fades out after 5 seconds. However, if I click the button again within those 5 seconds, the second notification gets queued up and displays once the first one has faded out.
My desired functionality is as follows: Upon pressing the button, the notification should display for 5 seconds. If I press the button again within this timeframe, the first notification should immediately disappear and only the new one should appear.
For a demonstration, check out the FIDDLE attached. FIDDLE