Вам нужно .stop()
, чтобы убрать задержку из очереди, например:
function notify(data, type) {
switch(type) {
case "success":
$('#notify').html(data)
.removeAttr("style")
.addClass('notifySuccess')
.click(function() {
$("#notify").stop(true, true).fadeOut();
})
.delay(5000).fadeOut();
break;
case "error":
$('#notify').html(data)
.removeAttr("style")
.addClass('notifyFailure')
.click(function() {
$("#notify").stop(true, true).fadeOut();
})
.delay(5000).fadeOut();
break;
}
}
Кроме того, если у вас есть только success
и error
для типов, вы можете значительно сократить это, например так:
function notify(data, type) {
$('#notify').html(data)
.removeAttr("style")
.addClass(type == 'success' ? 'notifySuccess' : 'notifyFailure')
.delay(5000).fadeOut()
.click(function() {
$(this).stop(true, true).fadeOut();
});
}