How to Stop CSS Animations from Running While Prerendering?
Asked by
Trundler
I'm working on a presentation-style website and implemented prerendering for the next slide to enhance user experience. However, I've noticed that the CSS animations are being executed while the page is still in the background and not visible to users. Is there a way to prevent this from happening?
Answers
Another approach is to apply the animation class to your slide only when it becomes active. This would prevent animations from running in the background, but you'd need some JavaScript to manage the active state.
Reply to this answer
You might want to check out the animation-timeline property found on MDN to manage when your animations run, but that largely depends on how you're implementing prerendering. Alternatively, you could use JavaScript along with an Intersection Observer to control when animations play.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions