While a div is 3d rotating, I’m trying to change its content in the exact moment when it is invisible.
My method is to rotate the parent (#card) on hover for 1 second and have two children (#front and #back) change their opacity with a delay of 0.5 seconds:
#card {
width: 200px;
height: 200px;
transition: 1s;
transform: rotate3d(0, 1, 0, 0deg);
}
#card:hover {
transform: rotate3d(0, 1, 0, 180deg);
}
#card>div {
transition-duration: 0s;
transition-delay: 0.5s;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
#card #front {
opacity: 1;
background: yellow;
}
#card #back {
opacity: 0;
transform: rotate3d(0, 1, 0, 180deg);
background: grey;
}
#card:hover #front {
opacity: 0;
}
#card:hover #back {
opacity: 1;
}
<div id="card">
<div id="front">
front
</div>
<div id="back">
back
</div>
</div>
https://jsfiddle.net/zpfheL14/1/
But the opacity-change happens too late, resulting in a glitchy-looking animation. Is there a way to reliably make the "animation" of the children happen in the right moment?
2
Answers
For me, the issue got solved with removing transition delay. and adding transition duration as 0.5s.
But I still face some glitch, because of container being rotated. try to keep a static container to which you add the :hover action. Can rotate the child (with no hover action).
Did this modicifation here: https://jsfiddle.net/dhbtjc1a/
I don’t know if you just want a flip card but if you do, you can try the following example. The Key CSS properties we use here are
transform-style: preserve-3d
andbackface-visibility: hidden
.