Reputation: 175
I created a mockup of the situation because I wasn't able to create a testable version so easily. But to get the gist:
@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);
}
<div class="main">
<div class="card">
<div class="front"></div>
<div class="back"></div>
</div>
</div>
Hopefully this is enough to know where the issue is.
CodePen: https://codepen.io/anon/pen/owvqQP/
EDIT Well. It's probably this thing: css z-index lost after webkit transform translate3d
But I still can't get it to work. The only solution would be to use position: relative;
and top: 0;
and top: -3rem;
for the animations..
Upvotes: 2
Views: 208
Reputation: 18434
Looks like you forgot -webkit-
prefix. Also recommend using translate3d for hardware acceleration. Try this way:
@-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);
}
Upvotes: 2