I know we can stop a finite css animation via animation-fill-mode: forwards;
. However, how to achieve the same effects for infinite animations? For example, for the following snippets, when pointerup
is fired, how to stop the animation at 360deg
state?
document.addEventListener("pointerup", () => {
const div = document.getElementsByTagName("div")[0];
//
});
div {
width: 100px;
height: 100px;
background: blue;
position: relative;
animation: ani 5s infinite;
}
@keyframes ani {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
<div></div>
Appendix:
- I know we can use timer in JS, and check whether
pointerup
is raised in each timer interval, however a solution with pure css or least js involved is preferred. - We should ensure the solution works well in modern browsers, such as Google Chrome and Microsoft Edge.