gpt4 book ai didi

jquery - 不透明度 0.5 除了这个 dd

转载 作者:太空宇宙 更新时间:2023-11-04 14:47:23 25 4
gpt4 key购买 nike

我想将主体不透明度更改为 0.5,但选择“dd”的聚焦区域除外。在 Backbone 中使用 coffeescript;

我尝试并搜索了示例; body 变化但不是 'dd'。

我的代码是:

@$el is selected dd

...

showhide:->
$('body').css({opacity:0.5});
@$el.css({opacity:1});

...

最佳答案

您尝试做的事情不会奏效。如果我们看一下 opacity specs我们会看看为什么不:

3.2. Transparency: the ‘opacity’ property

Opacity can be thought of as a postprocessing operation. Conceptually, after the element (including its descendants) is rendered into an RGBA offscreen image, the opacity setting specifies how to blend the offscreen rendering into the current composite rendering.
[...]
If the object is a container element, then the effect is as if the contents of the container element were blended against the current background using a mask where the value of each pixel of the mask is <alphavalue>.

因此,如果您设置 <body> 的不透明度到 0.5,那么浏览器将呈现所有 <body> (包括它的 child ,所以包括你的 @$el ),然后将它合成到浏览器窗口中,alpha channel 值为 0.5。结果是整个页面将以半透明呈现。改变内部某些东西的不透明度 <body>没关系,因为 child 的不透明度将在 child 被渲染成 <body> 时应用。然后 <body>之后将应用的不透明度。

考虑这个纯 HTML/CSS 示例:

<div id="outer">
<div id="inner"></div>
</div>

#outer {
/* ... */
opacity: 0.5;
}
#inner {
/* ... */
opacity: 1.0;
}

因为 #inner 整个东西看起来是半透明的不透明度实际上是“相对于其父级的不透明度”,而不是“相对于浏览器窗口的不透明度”。

演示:http://jsfiddle.net/ambiguous/WtAvx/

您将不得不改变您的方法。例如,您可以定位 opacity: 0.5您的 @$el 之间的元素和 <body>具有这样的结构:

<div id="outer"></div>
<div id="inner"></div>

和:

#outer {
/* ... */
position: absolute;
top: 0;
left: 0;
opacity: 0.5;
}
#inner {
/* ... */
position: absolute;
top: 50px;
left: 50px;
opacity: 1.0; /* You don't really need this */
}

演示:http://jsfiddle.net/ambiguous/Jsd7q/

您可能需要使用 stacking order并插入一个绝对定位的 <div>opacity: 0.5在你的元素和 <body> 之间但我不能再说了,请提供您问题中的细节。

关于jquery - 不透明度 0.5 除了这个 dd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17743643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com