Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not 100% sure I understand your problem. What I think you are saying is you want to:</p> <ol> <li>display messages that self-dismiss</li> <li>if a message arrives while one is being displayed, it is queued</li> <li>once the current message self-dismisses, there should be a short pause before displaying the next</li> </ol> <p>With those goals in mind:</p> <pre><code>//message queue var msgqueue = Array(); //displaying flag var msgdisplaying = null; //clear message and hide box/bar function clearMessage() { msgdisplaying = null; $('#msgbox').css('display','none'); } //queue message, start display if no message showing function displayMessage(msg) { msgqueue.push(msg); if (msgdisplaying === null) showMessage(); } //display message and set dismiss/delay timers function showMessage() { if (msgqueue.length &gt; 0) { $("#msgbox").html("&lt;h1&gt;" + msgqueue.shift() + "&lt;/h1&gt;").css('display','block'); //dismiss this message after 3 seconds setTimeout("clearMessage();",3000); //display next message (if any) 0.1 seconds after dismissing msgdisplaying = setTimeout("showMessage();", 3100); } } </code></pre> <p><a href="http://jsfiddle.net/33e3u/1/" rel="nofollow">jsfiddle</a></p> <p>If you are going to use the jQuery <a href="http://www.w3schools.com/jquery/eff_animate.asp" rel="nofollow"><code>.animate</code></a> function to animate showing/hiding the message div, set the timeout for the next block using the callback argument to avoid timeouts firing during the animation</p> <pre><code>//show $("#msgbox").html("&lt;h1&gt;" + msgqueue.shift() + "&lt;/h1&gt;") $("#msgbox").animate({ 'opacity': 1 }, 500, 'swing', function() { msgdisplaying = setTimeout("dismissMessage();", 3000) }); //hide $("#msgbox").animate({ 'opacity': 0 }, 500, 'swing', function(){ if (msgqueue.length &gt; 0) msgdisplaying = setTimeout("showMessage();", 1000) } else { msgdisplaying = null }); </code></pre> <p><a href="http://jsfiddle.net/33e3u/3/" rel="nofollow">jsfiddle</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload