【发布时间】:2017-01-30 15:38:15
【问题描述】:
我已经构建了一个函数,它会在每次发送 ajax 请求时显示一个通知,我只需调用 showAjaxAlert() 函数:
function showAjaxAlert(message, type) {
var rand = randomNumber(100000, 1000000);
document.getElementById('notification_area').innerHTML = document.getElementById('notification_area').innerHTML + '<div class="ajax-notification ajax-notification-' + type + ' ajax-notification-' + rand + ' alert">' + message + '</div>';
$('.ajax-notification-' + rand).delay(500).fadeOut('slow');
}
我为每个 div 使用一个随机数来跟踪我淡出的内容,这里是随机数函数:
function randomNumber(min, max)
{
return Math.floor(Math.random()*(max-min+1)+min);
}
我将所有 ajax 通知存储在 1 个父 div 中,id 为“notification_area”
<div id="notification_area"></div>
这是我的 CSS:
#notification_area {
position: fixed;
top: 2em;
opacity: 0.8;
right: 2em;
}
.ajax-notification{
color: #fff;
background-color: red;
}
但问题是,如果第一个警报在另一个警报显示之前没有消失,它会永远留在那里,只有最近的警报会消失,就像我必须等待上一个警报消失才能消失一样发送另一个 ajax 警报。为什么会发生这种情况,有什么办法可以解决吗?
【问题讨论】:
-
你想在显示新通知之前淡出所有通知吗??
-
如果我在之前的通知淡出之前启动另一个通知,我只是不希望之前的通知卡住并且不淡出。现在,如果我在第一个淡出之前启动通知(第二个),第二个将淡出,而第一个将卡在那里。
标签: javascript jquery html css ajax