jQuery(“#wrapper”).css({ 不透明度: 0.5 })
我刚刚对纯色的 #wrapper
div
应用了不透明度:
jQuery("#wrapper").css({ opacity: 0.5 })
这很好用,但我不希望他们的子 div
继承不透明度。如何在不使用 PNG 透明度 hack 的情况下避免这种行为?
I just applied a opacity to a #wrapper
div
with a solid color:
jQuery("#wrapper").css({ opacity: 0.5 })
This works nicely, but I don't want their children div
s to inherit the opacity. How do I avoid this behavior without using PNG transparency hacks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不透明度始终由后代元素继承。没有办法避免它,这不是由于 jQuery,而是由于不透明度的工作方式。
Opacity is always inherited by descendant elements. There are no way to avoid it, and it isn't due to jQuery, but the way opacity works.
克隆元素(和子元素)并获取偏移量。然后在原始元素中,隐藏所有内部元素。现在设置不透明度。对于克隆的元素,将其放置在原始元素的顶部(使用位置和偏移量),但这次隐藏克隆元素的背景。
Clone the element (and children) and get the offsets. Then in the original element, hide all the inner elements. Now set the opacity. With the cloned element, place it on top of the original element (using position and the offsets), but this time hide the background to the cloned element.