除了使用jQuery之外,如何淡化容器中的所有div?

时间:2011-09-09 13:22:18

标签: jquery html fading

我有这个:

$("#id").click(function() {
    $('.swoosh div').fadeOut('fast', function(){
        $('.template').fadeIn('fast');
    });
});

.swoosh是容器div,和 .template是我想点击#id时要保留的div,而.swoosh内的所有其他div都会消失。

我觉得有点傻,但我已经玩了好几年也无济于事。请帮助一个兄弟。

5 个答案:

答案 0 :(得分:4)

您可以使用not [doc]选择器

$("#id").click(function() {
    $('.swoosh div:not(.template)').fadeOut('fast');
});

答案 1 :(得分:2)

    $('.swoosh div[class!="template"]').fadeOut('fast');

答案 2 :(得分:0)

$("#id").click(function() {
    $('.swoosh div').fadeOut('fast');
    $('.template').fadeIn('fast');
});

答案 3 :(得分:0)

由于您正在淡出容器DIV,因此DIV中的所有元素也逐渐淡出似乎是合乎逻辑的。因此,您可以做的是从容器div中提取元素并将其放在DOM中的其他位置,然后将容器DIV淡出。这样,它应该保持可见。

答案 4 :(得分:0)

旧问题,但这也可行

$("#id").click(function() {
    $('.swoosh div').not($('.template')).fadeOut('fast');
});