问题
我试图让一层似乎像一面墙掉下来,露出了它后面的一层.我设置了两个固定的div位置. “Wall”div的z-index为9999,“Background”div的z-index为0;
在我测试的Webkit浏览器(Safari / IOS)中,似乎一旦动画在“墙”上开始,z索引丢失或忽略,导致“墙”图层突然消失在背景div后面.
关于如何保存层的z-索引的任何想法?提前致谢!
- <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的区别.
解决方法
我的旋转元素不适合有背景的邻居,但我通过应用来修复它
- transform: translateZ(1000px);
- transform-style: preserve-3d;
到旋转元件的父母. Safari现在认为它的背景是1000px.