I am having trouble getting a button to trigger an animation. Currently, the animation only plays once when the page is refreshed and doesn't repeat on subsequent clicks of the button.
function initiateAnimation(el){ document.getElementById("animationBox").style.animationPlayState = "running";
}
#animationBox {
width: 100px;
height: 100px;
background: red;
position: relative;
animation-name: spin;
animation-duration: 3s;
animation-delay: 1s;
animation-play-state: paused;
}
@keyframes spin {
0% {background-color: yellow;}
50% {background: purple;}
100%{background: red;}
}
<div id="animationBox"></div>;
<div><button onclick="initiateAnimation(this)" class="fas fa-play"> Click Me!</button></div>