问题
我试图让一个图层看起来像是一堵倒塌的墙,露出它后面的图层。我设置了两个固定的 div 位置。 “Wall”div 的 z-index 为 9999,“Background”div 的 z-index 为 0;
在我测试过的 Webkit 浏览器 (Safari/IOS) 中,似乎一旦动画在“墙”上开始,z-index 就会丢失或被忽略,导致“墙”层突然消失在背景 div 后面。
关于如何保留图层的 z 索引的任何想法?提前致谢!
示例代码 (注意:底部的 jsFiddle)
网页代码
<div id="wall">
This is the wall
</div>
<div id="background">
This is the background
</div>
<button id="start" style="float: right;">
Flip Down
</button>
一些启用按钮的javascript
$('#start').click(function(){
alert('Should Fall Down like a wall, revealing the background');
$('#wall').addClass('animated flipDown');
});
CSS 代码(摘自 animate.css)
#wall{
background-color: #F00;
width: 100px;
height: 100px;
position:fixed;
top:0;
left:0;
z-index: 9999;
}
#background{
background-color: #00F;
width: 100px;
height: 100px;
position:fixed;
top:0;
left:0;
z-index: 0;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
/*** flipDown ***/
@-webkit-keyframes flipDown {
0% {
-webkit-transform: perspective(400px) rotateX(0deg);
transform: perspective(400px) rotateX(0deg);
-webkit-transform-style: flat;
opacity: 1;
}
100% {
-webkit-transform: perspective(400px) rotateX(90deg);
transform: perspective(400px) rotateX(90deg);
-webkit-transform-style: flat;
opacity: 1;
}
}
@keyframes flipDown {
0% {
-webkit-transform: perspective(400px) rotateX(0deg);
-ms-transform: perspective(400px) rotateX(0deg);
transform: perspective(400px) rotateX(0deg);
opacity: 1;
}
100% {
-webkit-transform: perspective(400px) rotateX(90deg);
-ms-transform: perspective(400px) rotateX(90deg);
transform: perspective(400px) rotateX(90deg);
opacity: 0;
}
}
.flipDown {
-webkit-animation-name: flipDown;
animation-name: flipDown;
-webkit-backface-visibility: visible !important;
-ms-backface-visibility: visible !important;
backface-visibility: visible !important;
-webkit-transform-origin: bottom;
-ms-transform-origin: bottom;
transform-origin: bottom;
}
jsFiddle
查看 Safari 与 Chrome 的区别。
原文由 zeroSkillz 发布,翻译遵循 CC BY-SA 4.0 许可协议
我的旋转元素不适合与背景相邻,但我通过应用修复了它
到旋转元素的父级。 Safari 现在认为它在背景前面 1000 像素。