With this CSS I make the animation of the three Divs, said animation consists of putting the second div on top of the first, passing the first one back and moving the third div to the second position and thus showing all the divs one by one.
html, body { position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: hidden; }
.card{
position: absolute;
transform: scale(0.75);
height:200px;
width:300px;
animation-name: cards-animation;
animation-iteration-count:infinite;
animation-duration: 6s;
}
.card-blue{
background-color:blue;
animation-delay: 1s;
}
.card-red{
background-color:red;
animation-delay: 3s;
}
.card-green{
background-color:green;
animation-delay: 5s;
}
@keyframes cards-animation {
0% {
transform: scale(0.75) ;
z-index: 0;
}
9% {
transform: scale(0.9) translateY(40px);
z-index: 2;
}
33% {
transform: scale(0.9) translateY(40px);
z-index: 2;
}
42% {
transform: translateY(80px);
z-index: 3;
}
66% {
transform: translateY(80px);
z-index: 3;
opacity: 1;
}
75% {
transform: translateY(130px);
opacity: 0;
}
80% {
transform: scale(0.75) translateY(40px);
opacity: 0;
z-index: 1;
}
90% {
transform: scale(0.75);
opacity: 1;
z-index: 1;
}
}
<div class="card card-blue"></div>
<div class="card card-red"></div>
<div class="card card-green"></div>
What I need is to know how I can pass the CSS code that makes that animation to a Javascript code, I mean to have the same animation but instead of doing it with CSS, do it with Javascript in order to have more control over it.
<div class="card card-blue"></div>
<div class="card card-red"></div>
<div class="card card-green"></div>