【问题标题】:Safari CSS issue with overlayed animations覆盖动画的 Safari CSS 问题
【发布时间】:2018-03-06 06:39:37
【问题描述】:

我有一个简单的卡片翻转动画,它在我测试过的浏览器上运行良好。

但是,当此卡片翻转动画发生在另一个也正在动画的 div 之上时,Safari 上会出现问题。出于某种原因,在 Safari 上,当卡片翻转时,它会消失在“背景 div”后面。我认为这可能是 z-index 问题,但从我的尝试来看不是。

为了使示例简单,背景 div 是灰色的。这个想法是在背景中产生发光效果。

下面是我的代码示例,我已经在 Chrome、Firefox 和 Edge 上测试过它工作正常,但是在 Safari 上翻转卡片时它会消失。

$(document).ready(function() {
  $('button').click(function() {
    $('.wrapper').toggleClass('flip');
  });
});
.perspective {
  perspective: 1000px;
  margin: 50px;
  position: relative;
  width: 175px;
  height: 250px;
}

.some-bg {
  background-color: #ccc;
  background-position: center;
  width: 100%;
  height: 100%;
  position: absolute;
  animation: test-bg-animation 1s infinite linear;
}

@keyframes test-bg-animation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.wrapper {
  width: 125px;
  height: 175px;
  border: 1px solid blue;
  position: absolute;
  transform-style: preserve-3d;
  transition: all 250ms;
  top: 35px;
  left: 25px;
}

.wrapper.flip {
  transform: rotateY(180deg);
}

.card-face {
  width: 100%;
  height: 100%;
  position: absolute;
  -webkit-backface-visibility: hidden;
}

.back {
  background-color: tomato;
}

.front {
  background-color: #bada55;
  transform: rotateY(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="perspective">
  <div class="some-bg"></div>
  <div class="wrapper">
    <div class="card-face front">Front</div>
    <div class="card-face back">Back</div>
  </div>
</div>
<button>Flip Me!</button>

【问题讨论】:

    标签: css safari css-animations card-flip


    【解决方案1】:

    您可以通过将 .some-bg.wrapper div 嵌套到具有相对定位父级的绝对定位 div 中来解决此问题。

    请看这个小提琴的例子: https://jsfiddle.net/voLzv68w/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      • 2022-08-18
      • 2021-05-16
      相关资源
      最近更新 更多