I am making a mini javascript game that flips over matching pairs of cards. I have the flipping rotateY(180)
working fine on the card element.
However when two cards dont match I have a shake animation and flip the cards back. My problem is the cards flip back rotateY(0)
and then shakes even though I have it to stay at rotateY(180)
until after 50%
This is the css for the card flip.
.card {
position: relative;
height: 6rem;
border-radius: 5px;
transform: scale(1);
transform-style: preserve-3d;
transition: transform .5s;
box-shadow: 5px 5px 0px 0px rgba(218,218,218,1);
}
.card:active {
transform: scale(0.97);
transition: transform .2s;
}
.card-face {
position: absolute;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
border-radius: 5px;
}
.card.flip {
transform: rotateY(180deg);
}
Now I add the animation to shake the card and flip it back:
.card-shake {
-webkit-animation: card-shake 1.8s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
animation: card-shake 1.8s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
}
@keyframes card-shake {
0% {
-webkit-transform: translateX(0) rotateY(180);
transform: translateX(0) rotateY(180);
}
5%,
15%,
25%,
35% {
-webkit-transform: translateX(-10px);
transform: translateX(-10px);
}
10%,
20%,
30% {
-webkit-transform: translateX(10px);
transform: translateX(10px);
}
40% {
-webkit-transform: translateX(8px);
transform: translateX(8px);
}
45% {
-webkit-transform: translateX(-8px);
transform: translateX(-8px);
}
50% {
-webkit-transform: translateX(-8px) rotateY(180);
transform: translateX(-8px) rotateY(180);
}
100% {
-webkit-transform: translateX(-8px) rotateY(0);
transform: translateX(-8px) rotateY(0);
}
}
question from:
https://stackoverflow.com/questions/65833703/css-keyframe-rotatey180-resets-to-rotatey0-problem 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…