I have this Html code and I want all the animations to be played after clicking on the link :
document.querySelector('.play').addEventListener('click', function() {
document.querySelector('.trans-up').style.animationPlayState = 'running';
document.querySelector('.trans-mid').style.animationPlayState = 'running';
document.querySelector('.trans-down').style.animationPlayState = 'running';
});
.trans-up {
animation: trans-up-anim 1.8s forwards;
}
.trans-down {
animation: trans-dow -anim 1.5s forwards;
}
.trans-mid {
animation: trans-down-anim 1.3s forwards;
}
@keyframes trans-up-anim {
0% {
top: -100%
}
}
@keyframes trans-down-anim {
0% {
bottom: -100%
}
}
<a class="play">click on me<a>
<div class="trans-up"></div>
<div class="trans-mid"></div>
<div class="trans-down"></div>
2
Answers
your code might not run due to the following reason
2.Its important you give your div a position of relative, and also, you can add a transition to your CSS. A sample is provided below for you to use have a guide
click on me<a>
the problem arises from the fact that you have not given content to the divs you want to animate and that is why the animations do not work