Note that there are some explanatory texts on larger screens.

plurals
  1. POEleminate the delay when no text is set
    text
    copied!<p>I've prepared a little code snipped which works quite perfectly - except that I'd like to eliminate the pause when setting the text to an empty string (between "hello world" and "hello universe"). </p> <p>Can anyone figure out how? Must admit - I didn't... :-(</p> <p><a href="http://jsfiddle.net/DCAHH/DRLgE/" rel="nofollow">Sandbox is here</a></p> <pre><code> &lt;!-- Put the notificationBar somewhere in your HTML --&gt; &lt;div id="notificationBar"&gt;&lt;/div&gt; /* whatever you want it to look like - keep the display: none; */ #notificationBar { display: none; padding: 1em; border-radius: 5px; background-color: red; color: white; } </code></pre> <p>The jQuery</p> <pre><code> // Set it up! var notificationTextToggeled = 0; // Always 0 var notificationDelay = 2000; // Whatever delay you want, in ms (1000 = 1 sec) // Here goes your code... intersperse it with notification messages you // want to present to the user... just like below notificationToggle ('Hello World'); notificationToggle (''); notificationToggle ('Hello Universe'); notificationToggle ('Hello Superman'); notificationToggle (''); // This function will do all the displaying and will keep an eye // on not waving too many messages to the user in too short time: // Each (not empty) message text will be displayed for at least the delay time function notificationToggle (text) { var know = $.now(); if (text != $('#notificationBar').html().length &amp;&amp; know &lt; (notificationTextToggeled + notificationDelay )) $('#notificationBar').delay(notificationDelay, "fx"); $('#notificationBar').text().length $('#notificationBar').slideUp('slow'); $.queue($("#notificationBar")[0], "fx", function () { $(this).html(text); $.dequeue(this); }); if (text) $('#notificationBar').slideDown('slow'); notificationTextToggeled = know; } </code></pre>
 

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