so I’ve been playing around with CSS for quite some time now but I face a challenge that I can’t quite solve:
I have 2 logos that I need to animate. The animation has to basically be a 2-way flipY that makes one logo rotate along the Y axis and when at 180 degrees the logo has to be swapped to the 2nd logo thats positioned at 180 degrees too and rotates towards logo’s 1 first position (from 180 to 360 degrees) and then pauses. I tried doing my best but failed miserably.
.logo1,
.logo2 {
position: absolute;
top: 0;
left: 0;
width: 25vw;
height: auto;
transform-origin: center;
opacity: 0;
}
.logo1 {
animation: rotate1 4s linear infinite;
opacity: 1;
}
.logo2 {
animation: rotate2 4s linear infinite;
}
@keyframes rotate1 {
0% {
transform: rotateY(0deg);
}
50% {
transform: rotateY(180deg);
}
100% {
transform: rotateY(180deg);
}
}
@keyframes rotate2 {
0% {
transform: rotateY(180deg);
}
50% {
transform: rotateY(360deg);
}
53% {
transform: rotateY(360deg);
opacity: 0;
}
56% {
opacity: 1;
}
100% {
transform: rotateY(360deg);
}
}
/* Swap logo 1 and logo 2 at 50% of the animation */
.logo1 {
animation-name: swap1;
animation-duration: 8s;
}
.logo2 {
animation-name: swap2;
animation-duration: 8s;
animation-delay: 4s;
}
@keyframes swap1 {
0% {
transform: rotateY(0deg);
opacity: 1;
}
50% {
transform: rotateY(180deg);
opacity: 0;
}
51% {
opacity: 0;
}
53% {
opacity: 1;
}
100% {
transform: rotateY(180deg);
opacity: 1;
}
}
@keyframes swap2 {
0% {
transform: rotateY(180deg);
opacity: 0;
}
50% {
transform: rotateY(360deg);
opacity: 0;
}
53% {
opacity: 1;
}
56% {
opacity: 0;
}
100% {
transform: rotateY(360deg);
opacity: 0;
}
}
<div class="logo-container">
<img class="logo1" src="/logo1.png">
<img class="logo2" src="/logo2.png">
</div>
2
Answers
Working snippet:
This should work (don’t forget to put two logos in a root folder):
HTML:
CSS: