我有这个:
$("#id").click(function() {
$('.swoosh div').fadeOut('fast', function(){
$('.template').fadeIn('fast');
});
});
.swoosh
是容器div,
.template
是我点击时想要保留的div #id
,而里面的所有其他div都.swoosh
消失了。
我觉得有点傻,但是我玩了很多年都无济于事。请大哥帮忙。
您可能可以使用not
[doc]选择器
$("#id").click(function() {
$('.swoosh div:not(.template)').fadeOut('fast');
});
$('.swoosh div[class!="template"]').fadeOut('fast');
$("#id").click(function() {
$('.swoosh div').fadeOut('fast');
$('.template').fadeIn('fast');
});
由于您正在淡出容器 DIV,因此该 DIV 中的所有元素也正在淡出似乎是合乎逻辑的。因此,您可以做的是从容器 div 中提取元素并将其放置在 DOM 中的其他位置,然后再将容器 DIV 淡出。这样,它应该保持可见。
老问题,但这也可以
$("#id").click(function() {
$('.swoosh div').not($('.template')).fadeOut('fast');
});