My awesome graphic animation is in CSS and SVG format. I've been struggling to add a play/pause button to control the animation on click. Here is what I have so far:
.animation1 {
--animation-delay: 0.1s;
animation: ani_keyframes 1.8s linear infinite var(--animation-delay) paused;
}
.playani {
animation-play-state: running;
}
.animation1:hover {
animation: none;
fill: #666;
}
@keyframes ani_keyframes {
...
...
}
<script type="text/javascript">
var button = document.getElementById('button-ani'),
test_ani = document.getElementByClassName('animation1');
button.onclick = function(){
test_ani.classList.toggle('playani');
}
</script>
<div id="animation1_wrapper">
<svg id="animation1" width="100%" height="100%" viewBox="0 0 418 255" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="ani_graphic">
<path class="animation1" d="M263.46 25.3801C257.63 29.2001 252.88 33.7801 249.33 37.8001H263.46V25.3801Z" fill="#000"></path>
.....
.....
.....
</g>
</svg>
</div>
<button id="button-ani">Toggle Animation Play State</button>