jQuery:子元素在 IE 中消失并带有 $('.parent_class') 不透明度效果
我有这个 html:
<div class="foo parent">
<div class="child"></div>
</div>
和一些 css:
.foo{
position:absolute;
left: -117px;
background:#000000 none repeat scroll 0 0;
color:#FFFFFF;
z-index:8;
}
.parent{
top:23px;
width:100px;
height:30px;
display:none; #parent and child to start out hidden
}
.child{
position:relative;
left:94px;
top:5px;
height:20px;
width: 110px;
background:#000000;
z-index:9;
}
我希望这个父级和子级一起淡入,并最终得到不透明度:0.50。 Firefox 做得很好,但 IE 遇到了麻烦:当我在父级上执行 fadeIn() 或 fadeTo() 或什至只是简单地应用 .css('opacity','0.50') 时,父级会呈现,而子级不会呈现t。
$('.parent').fadeTo('fast',0.50)
-->导致父级淡入但子级永远不会出现。
$('.parent').fadeIn('fast')
-->父母出现,没有孩子
$('.parent').css('opacity','0.55')
$('.parent').show()
-->父级显示为不透明,子级永远不会出现
$('.parent').show()
-->父级和子级看起来很好(但没有动画或透明度)。如果我
$('.parent').css('opacity','0.55') or $('.parent').fadeTo('fast', 0.50)
之后这样做,父级会得到效果,而子级会消失。
父级和子级如何一起动画并共享不透明度属性?
I have this html:
<div class="foo parent">
<div class="child"></div>
</div>
with some css:
.foo{
position:absolute;
left: -117px;
background:#000000 none repeat scroll 0 0;
color:#FFFFFF;
z-index:8;
}
.parent{
top:23px;
width:100px;
height:30px;
display:none; #parent and child to start out hidden
}
.child{
position:relative;
left:94px;
top:5px;
height:20px;
width: 110px;
background:#000000;
z-index:9;
}
I want this parent and child to fade in together, and end up with opacity:0.50. Firefox does this just fine, but IE gives trouble: When I do a fadeIn() or fadeTo() or just even simply apply .css('opacity','0.50') on the parent, the parent renders and the child doesn't.
$('.parent').fadeTo('fast',0.50)
--> causes the parent to fade in but the child never appears.
$('.parent').fadeIn('fast')
--> parent appears, no child
$('.parent').css('opacity','0.55')
$('.parent').show()
--> parent appears with opacity, child never appears
$('.parent').show()
--> parent and child appear just fine (but with no animation or transparency). If I do
$('.parent').css('opacity','0.55') or $('.parent').fadeTo('fast', 0.50)
afterward, the parent gets the effect and the child disappears.
How can a parent and child be animated together and share opacity properties?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不尝试在选择器中同时指定父元素和子元素,同时将effect/css应用于两者:
Why not try specifying both the parent and child elements within your selector, applying the effect/css to both at the same time:
我已经成功地预先定义了元素的透明度,然后在父元素上执行 fadeIn() 。如果我这样做:
这就会达到我想要的效果。然而奇怪的是,我必须先设置孩子的不透明度。如果我同时设置它们,
或者首先将其设置在父级上,则当我执行 fadeIn() 时,子级会像以前一样消失。
I've had some success with defining the transparency on the elements before-hand and then doing a fadeIn() on the parent element. If I do:
this gives the effect I'm going for. However it's weird, I have to set the opacity on the child first. If I set them both at the same time
or if I set it on the parent first, when I do the fadeIn() the child disappears as before.