After designing a SVG landscape with an animation triggered by clicking the sun, I encountered an issue where the animation only works once. Subsequent clicks do not result in any animation.
Below is my current JavaScript code:
const sun = document.getElementById("sun");
const stage = document.getElementById("stage");
sun.addEventListener("click", function() {
sun.style.animationPlayState = "running";
stage.style.animationPlayState = "running";
});
sun.addEventListener("animationend", function() {
// Reset sun to initial position
sun.setAttribute("cx", "700");
sun.setAttribute("cy", "100");
// Pause animations for both sun and stage
sun.style.animationPlayState = "paused";
stage.style.animationPlayState = "paused";
});