【发布时间】:2011-09-14 13:37:13
【问题描述】:
我已经准备了一小段代码,它工作得非常完美 - 除了我想在将文本设置为空字符串(“hello world”和“hello world”之间)时消除暂停。
谁能弄清楚怎么做?必须承认 - 我没有...... :-(
<!-- Put the notificationBar somewhere in your HTML -->
<div id="notificationBar"></div>
/* whatever you want it to look like - keep the display: none; */
#notificationBar {
display: none;
padding: 1em;
border-radius: 5px;
background-color: red;
color: white;
}
jQuery
// 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 && know < (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;
}
【问题讨论】:
标签: jquery notifications queue delay