【发布时间】:2012-03-23 15:01:28
【问题描述】:
所以我有这段代码,它在 AJAX 请求之后在 print_info() 函数中调用;
'print_info' : function(message,type) {
$('.load').hide();
$('<div>'+message+'</div>').insertAfter('#loader').addClass('autoHideBox '+type).fadeIn("slow").delay(2000).fadeOut("slow", function() { $(this).remove(); });
},
如您所见,div 会在几秒钟内淡入淡出,我的问题是,即使我添加了这段代码:
.click(function() { $(this).fadeOut("slow", function() { $(this).remove(); }); } )
div 根本不会淡出/移除。你能清除这个吗?因为我对这件事有点困惑。
问候, 杜鲁曼埃迪
后期编辑:
我让它与 .on("click", callback) 一起使用,但是,在回调中淡出并删除它是行不通的。
所以,为了让它正常工作,你可以在 on("click" 的回调中做任何你需要做的事情,只需在 .on() 之前添加 stop(true,true).on("click" ",回调);
'print_info' : function(message,type) {
$('.load').hide();
$('<div>'+message+'</div>')
.insertAfter('#loader')
.addClass('autoHideBox '+type)
.fadeIn("slow")
.delay(2000)
.fadeOut("slow", function() { $(this).remove(); })
.on('click', function() {
$(this).stop(true,true).fadeOut("slow", function() { $(this).remove(); })
});
},
【问题讨论】: