使用父变换的CSS变换在iOS Safari上不起作用

时间:2017-06-02 00:30:05

标签: html css sass

我创建了一个情节模型,因为我无法轻松创建可测试版本。但要获得要点:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>Thymeleaf</title>
</head>
<body>
<div th:if="#{var1}"></div>

</body>
</html>
@keyframes mainFadeIn {
  0% {
    opacity: 0;
    transform: translateY(-3rem);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

// If I use this, without the transform, then everything works.
// 
// @keyframes mainFadeIn {
//   0% {
//     opacity: 0;
//   }
// 
//   100% {
//     opacity: 1;
//   }
// }

.main {
  animation-name: mainFadeIn;
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-timing-function: linear;
  background-color: gray;
  width: 100%;
  height: 16rem;
  padding: 3rem;
}

.card {
  transition: transform 500ms;
  transform-style: preserve-3d;
  -webkit-transform-origin: 50% 50%;
  perspective: 200px; // Ignore
  margin: auto;
  width: 30rem;
  height: 10rem;
  background-color: lightblue;
  
  &.flipped {
    transform: rotateY(-180deg);
  }
}

.front,
.back {
  backface-visibility: hidden;
}

.back {
  transform: rotateY(-180deg);
}

希望这足以知道问题所在。

CodePen: https://codepen.io/anon/pen/owvqQP/

修改 好。这可能是这件事:css z-index lost after webkit transform translate3d

但我仍然无法让它发挥作用。唯一的解决方案是使用<div class="main"> <div class="card"> <div class="front"></div> <div class="back"></div> </div> </div>position: relative;以及top: 0;来制作动画。

1 个答案:

答案 0 :(得分:2)

您似乎忘记了-webkit-前缀。还建议使用translate3d进行硬件加速。试试这个:

@-webkit-keyframes mainFadeIn {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, -3rem, 0);
    transform: translate3d(0, -3rem, 0);
  }

  100% {
    opacity: 1;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}
@keyframes mainFadeIn {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, -3rem, 0);
    transform: translate3d(0, -3rem, 0);
  }

  100% {
    opacity: 1;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}

.main {
  -webkit-animation-name: mainFadeIn;
  -webkit-animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  -webkit-animation-timing-function: linear;
  animation-name: mainFadeIn;
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-timing-function: linear;
  background-color: gray;
  width: 100%;
  height: 16rem;
  padding: 3rem;
}

.card {
  transition: -webkit-transform 500ms;
  -webkit-transform-style: preserve-3d;
  transition: transform 500ms;
  transform-style: preserve-3d;
  -webkit-transform-origin: 50% 50%;
  -webkit-perspective: 200px; // Ignore
  perspective: 200px; // Ignore
  margin: auto;
  width: 30rem;
  height: 10rem;
  background-color: lightblue;

  &.flipped {
    -webkit-transform: rotateY(-180deg);
    transform: rotateY(-180deg);
  }
}

.front,
.back {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.back {
  -webkit-transform: rotateY(-180deg);
  transform: rotateY(-180deg);
}