【发布时间】:2010-12-28 13:25:00
【问题描述】:
我正在编写一个简单的 jQuery 插件,它在屏幕中心显示具有特定类的图像(单击时,全尺寸),图像周围有灰色覆盖层。当我们单击覆盖时,它会消失。现在我使用这段代码:
$("#overlay").click(function(){
$(this).animate({
opacity: "0"
}, 500, function(){
$(this).css({
display: "none"
});
});
$("#imgcontainer").animate({
opacity: "0"
}, 500, function(){
$(this).css({
display: "none"
});
});
});
imgcontainer 保存我们的图像。我试图使用这个更简单的代码,但它不起作用:
$("#overlay").click(function(){
$(this).add("#imgcontainer").animate({
opacity: "0"
}, 500, function(){
$(this).css({
display: "none"
});
});
});
为什么它不起作用?
更新:
正确代码:
$("#overlay").click(function(){
$("#imgcontainer").add(this).fadeOut();
});
非常感谢您的回复。这种行为(错误?)确实非常令人惊讶。
【问题讨论】:
标签: jquery jquery-animate add