简体   繁体   English

当主体受到影响时,如何在主体内的div中添加jquery .not()?

[英]How to add jquery .not() in a div inside the body when the body is the one being affected?

     $('#button').click(function(){
       $('body').css('-webkit-filter', 'blur(4px)');
     });

When button is clicked, body is turned blur, but i don't want the div inside the body to turn blurred as well. 单击按钮时,主体会变得模糊,但我也不想让主体内的div也变得模糊。 How to do that? 怎么做? can i do that with the .not() jquery function? 我可以使用.not()jQuery函数来做到这一点吗?

No, the not([selector]) function is used for discarding elements from the current jQuery selection. 不, not([selector])函数用于丢弃当前jQuery选择中的元素。 It can't be used for exempting an element from an effect that is applied to one of its ancestor elements. 它不能用于将元素豁免于应用于其祖先元素之一的效果。

You could try to apply the blur to everything inside the body, except the div itself. 您可以尝试将模糊应用于除div本身之外的体内所有物体。

$('body').children().not('div').toggleClass('blur');

Fiddle 小提琴

Maybe I misunderstand the question, but couldn't you just add 也许我误解了这个问题,但是您不能只是添加

$('#DIV').css('-webkit-filter', 'blur(0px)');

(where #DIV is the div you don't want blurred) and turn off the blurring on that specific element? (其中#DIV是您不希望模糊的div)并关闭该特定元素的模糊?

Edit: They were saying in the above answer that it couldn't be done, so maybe something like a container for everything except the div? 编辑:他们在上面的答案中说无法完成,所以除了div之外,其他所有东西都可能像一个容器吗?

http://jsbin.com/eDIPoYU/1/ http://jsbin.com/eDIPoYU/1/

I would use something like this. 我会用这样的东西。

   $('#button').click(function(){
       $('body').css('-webkit-filter', 'blur(4px)');
       $('body').find("div").css('-webkit-filter', 'blur(0px)');
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM