It's been a while since I asked a question here. So excuse me if I do anything wrong.
I have an issue with CSS animation. I would like my animation to keep repeating it self but without loosing the initial effects. However it seems like there is a bug either in my code or in CSS animation behavior.
After it completes first 2 rotate animations (spin, spinback) defined. The loop begins but the new animation is not as same as before.
My goal is to create rotate animation on 6 boxes in order, one at a time. When all boxes turned, they should start turning back to original state again in order, one by one.
Code:
/* -------------------------------------------------------- */
#loader {
width: 240px;
height: 100px;
}
.inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 2s;
transform-style: preserve-3d;
background-color: transparent;
}
.front,
.back {
position: absolute;
width: 80px;
height: 50px;
backface-visibility: hidden;
}
/* -------------------------------------------------------- */
#loader1 {
float: left;
width: 80px;
height: 50px;
perspective: 1000px;
background-color: transparent;
}
#loader1 .inner {
animation: spin 10s ease 0s infinite, spinback 10s ease 10s infinite;
-webkit-animation: spin 10s ease 0s infinite, spinback 10s ease 10s infinite;
}
#loader1 .front {
background-color: #db9834;
}
#loader1 .back {
background-color: #3498db;
transform: rotateY(180deg);
}
/* -------------------------------------------------------- */
#loader2 {
float: left;
width: 80px;
height: 50px;
perspective: 1000px;
background-color: transparent;
}
#loader2 .inner {
animation: spin 10s ease 1s infinite, spinback 10s ease 11s infinite;
-webkit-animation: spin 10s ease 1s infinite, spinback 10s ease 11s infinite;
}
#loader2 .front {
background-color: #db8834;
}
#loader2 .back {
background-color: #3488db;
transform: rotateY(180deg);
}
/* -------------------------------------------------------- */
#loader3 {
float: left;
width: 80px;
height: 50px;
perspective: 1000px;
background-color: transparent;
}
#loader3 .inner {
animation: spin 10s ease 2s infinite, spinback 10s ease 12s infinite;
-webkit-animation: spin 10s ease 2s infinite, spinback 10s ease 12s infinite;
}
#loader3 .front {
background-color: #db7834;
}
#loader3 .back {
background-color: #3478db;
transform: rotateY(180deg);
}
/* -------------------------------------------------------- */
#loader4 {
float: left;
width: 80px;
height: 50px;
perspective: 1000px;
background-color: transparent;
}
#loader4 .inner {
animation: spin 10s ease 3s infinite, spinback 10s ease 13s infinite;
-webkit-animation: spin 10s ease 3s infinite, spinback 10s ease 13s infinite;
}
#loader4 .front {
background-color: #db6834;
}
#loader4 .back {
background-color: #3468db;
transform: rotateY(180deg);
}
/* -------------------------------------------------------- */
#loader5 {
float: left;
width: 80px;
height: 50px;
perspective: 1000px;
background-color: transparent;
}
#loader5 .inner {
animation: spin 10s ease 4s infinite, spinback 10s ease 14s infinite;
-webkit-animation: spin 10s ease 4s infinite, spinback 10s ease 14s infinite;
}
#loader5 .front {
background-color: #db5834;
}
#loader5 .back {
background-color: #3458db;
transform: rotateY(180deg);
}
/* -------------------------------------------------------- */
#loader6 {
float: left;
width: 80px;
height: 50px;
perspective: 1000px;
background-color: transparent;
}
#loader6 .inner {
animation: spin 10s ease 5s infinite, spinback 10s ease 15s infinite;
-webkit-animation: spin 10s ease 5s infinite, spinback 10s ease 15s infinite;
}
#loader6 .front {
background-color: #db4834;
}
#loader6 .back {
background-color: #3448db;
transform: rotateY(180deg);
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotateY(0deg);
}
16% {
-webkit-transform: rotateY(180deg);
}
100% {
-webkit-transform: rotateY(180deg);
}
}
@keyframes spin {
0% {
-webkit-transform: rotateY(0deg);
}
16% {
-webkit-transform: rotateY(180deg);
}
100% {
-webkit-transform: rotateY(180deg);
}
}
@-webkit-keyframes spinback {
0% {
-webkit-transform: rotateY(180deg);
}
16% {
-webkit-transform: rotateY(0deg);
}
100% {
-webkit-transform: rotateY(0deg);
}
}
@keyframes spinback {
0% {
-webkit-transform: rotateY(180deg);
}
16% {
-webkit-transform: rotateY(0deg);
}
100% {
-webkit-transform: rotateY(0deg);
}
}
<div id="loader">
<div id="loader1">
<div class="inner">
<div class="front">
</div>
<div class="back"> </div>
</div>
</div>
<div id="loader2">
<div class="inner">
<div class="front"> </div>
<div class="back"> </div>
</div>
</div>
<div id="loader3">
<div class="inner">
<div class="front"> </div>
<div class="back"> </div>
</div>
</div>
<div id="loader4">
<div class="inner">
<div class="front"> </div>
<div class="back"> </div>
</div>
</div>
<div id="loader5">
<div class="inner">
<div class="front"> </div>
<div class="back"> </div>
</div>
</div>
<div id="loader6">
<div class="inner">
<div class="front"> </div>
<div class="back"> </div>
</div>
</div>
</div>
Just to make it more understandable I am trying to apply css flipcard method:
https://www.w3schools.com/howto/howto_css_flip_card.asp
On divs in order to create a look like something is loading...
The animation only gives timing to trigger keyframes in right timing then in key frames I am rotating divs and putting a wait time until oter divs finishes their rotation. So formula is 6 box in 10sec which is gonna be somewhere between (0% to 100%) so (100 / 6 = 16,6) which I take the animation as should end at 16% of the animation time.
spin 10s ease 1s infinite, spinback 10s ease 11s infinite
this means that we wait 1s then run spin for 10s (at the same time we waited 11s) then we run spinback AND we run at the same time spin again (the issue) – Temani Afif