I have an SVG set as a background image of an element. The first time the element is displayed, the animation plays correctly.
On subsequent displays (e.g. if a dupl
This has worked for me, Simply adding and removing "play" class to a div element by adding setTimeout to delay classList.add('play') so the class can be removed and then applied
CSS
@keyframes play60 {
0% {
background-position: 0px 0px;
}
100% {
background-position: -38400px 0px;
}
}
.shapeshifter {
animation-duration: 1000ms;
animation-timing-function: steps(60);
animation-fill-mode: forwards;
width: 640px;
height: 640px;
background-repeat: no-repeat;
}
.shapeshifter.play {
animation-name: play60;
}
JS:
document.getElementById('shape').addEventListener('mouseover', () => {
document.getElementById('shape').classList.remove('play')
setTimeout(() => {
document.getElementById('shape').classList.add('play');
}, 1)
})
HTML