1
如何在同一個div中連續顯示排隊的消息?目前的解決方案很糟糕,因爲它會立即顯示新的div。如何在定義的時間後在一個div中淡入淡出和淡出元素?
HTML:
<div id="alert-bar-container"></div>
<button id="show">First message</button>
<button id="next">Next message</button>
的JavaScript:
var timeout;
$("#show").click(function() {
alertBar("this appears first");
});
$("#next").click(function() {
alertBar("this should wait and show after first disappeared");
});
function alertBar(msg) {
var message_span = $('<span />').html(msg);
var wrap_bar = $('<div />').addClass('alert_bar');
$('#alert-bar-container').html(wrap_bar.append(message_span).hide());
clearTimeout(wrap_bar.data("timer"));
wrap_bar.clearQueue();
if (wrap_bar.filter(":hidden").length == 1) wrap_bar.fadeIn('fast');
wrap_bar.data("timer", setTimeout(function() {
wrap_bar.fadeOut("slow");
wrap_bar.remove();
}, 2500));
}
? – Hiral
獨立。即使調用了多次函數。 – roza