Вот моя функция:
var showMessage = (function() {
var i = 0;
var messCount = 0;
var maxMessCount = 3;//Количество возможных отображаемых сообщения одновременно
return function(type, msg, delay) {
if(messCount >= maxMessCount) {
var remElem = $('#showMess_'+(i-maxMessCount));
remElem.slideUp(300, function() {
alert('a');
//console.log('End anim, remove: ' + remElem.attr('id'));
//remElem.remove();
//messCount = messCount > 0 ? messCount - 1 : 0;
});
remElem.remove();
messCount = messCount > 0 ? messCount - 1 : 0;
}
$('.messageDiv').append('<div class="'+type.match(/\w+$/)+'" id="showMess_'+i+'" style="display: none;">'+msg+'</div>');
messCount++;
$('#showMess_'+i).slideDown(300, function(){
$(this).delay(delay).slideUp(300, function(){
if($(this).length) {
$(this).remove();
messCount = messCount > 0 ? messCount - 1 : 0;
}
});
});
i++;
return false;
}
})();