html5 – webkit转换在Safari上打破z-index

前端之家收集整理的这篇文章主要介绍了html5 – webkit转换在Safari上打破z-index前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
问题

我试图让一层似乎像一面墙掉下来,露出了它后面的一层.我设置了两个固定的div位置. “Wall”div的z-index为9999,“Background”div的z-index为0;

在我测试的Webkit浏览器(Safari / IOS)中,似乎一旦动画在“墙”上开始,z索引丢失或忽略,导致“墙”图层突然消失在背景div后面.

关于如何保存层的z-索引的任何想法?提前致谢!

示例代码
(注:jsFiddle在底部)

HTML代码

  1. <div id="wall">
  2. This is the wall
  3. </div>
  4.  
  5. <div id="background">
  6. This is the background
  7. </div>
  8.  
  9. <button id="start" style="float: right;">
  10. Flip Down
  11. </button>

一些javascript启用按钮

  1. $('#start').click(function(){
  2. alert('Should Fall Down like a wall,revealing the background');
  3. $('#wall').addClass('animated flipDown');
  4. });

CSS代码(从animate.css下载)

  1. #wall{
  2. background-color: #F00;
  3. width: 100px;
  4. height: 100px;
  5. position:fixed;
  6. top:0;
  7. left:0;
  8. z-index: 9999;
  9. }
  10.  
  11. #background{
  12. background-color: #00F;
  13. width: 100px;
  14. height: 100px;
  15. position:fixed;
  16. top:0;
  17. left:0;
  18. z-index: 0;
  19. }
  20.  
  21. .animated {
  22. -webkit-animation-duration: 1s;
  23. animation-duration: 1s;
  24. -webkit-animation-fill-mode: both;
  25. animation-fill-mode: both;
  26. }
  27.  
  28.  
  29. /*** flipDown ***/
  30.  
  31. @-webkit-keyframes flipDown {
  32. 0% {
  33. -webkit-transform: perspective(400px) rotateX(0deg);
  34. transform: perspective(400px) rotateX(0deg);
  35. -webkit-transform-style: flat;
  36. opacity: 1;
  37. }
  38.  
  39. 100% {
  40. -webkit-transform: perspective(400px) rotateX(90deg);
  41. transform: perspective(400px) rotateX(90deg);
  42. -webkit-transform-style: flat;
  43. opacity: 1;
  44. }
  45. }
  46.  
  47. @keyframes flipDown {
  48. 0% {
  49. -webkit-transform: perspective(400px) rotateX(0deg);
  50. -ms-transform: perspective(400px) rotateX(0deg);
  51. transform: perspective(400px) rotateX(0deg);
  52. opacity: 1;
  53. }
  54.  
  55. 100% {
  56. -webkit-transform: perspective(400px) rotateX(90deg);
  57. -ms-transform: perspective(400px) rotateX(90deg);
  58. transform: perspective(400px) rotateX(90deg);
  59. opacity: 0;
  60. }
  61. }
  62.  
  63. .flipDown {
  64. -webkit-animation-name: flipDown;
  65. animation-name: flipDown;
  66. -webkit-backface-visibility: visible !important;
  67. -ms-backface-visibility: visible !important;
  68. backface-visibility: visible !important;
  69. -webkit-transform-origin: bottom;
  70. -ms-transform-origin: bottom;
  71. transform-origin: bottom;
  72. }

的jsfiddle

http://jsfiddle.net/3mHe2/2/

查看Safari与Chrome的区别.

解决方法

我的旋转元素不适合有背景的邻居,但我通过应用来修复它
  1. transform: translateZ(1000px);
  2. transform-style: preserve-3d;

到旋转元件的父母. Safari现在认为它的背景是1000px.

猜你在找的HTML5相关文章