I currently have a loading indicator element that is consistently displayed on my webpage. It can be shown or hidden by adding or removing a specific class that adjusts its opacity and z-index. The element itself contains an image with a CSS animation.
My concern is that this setup may not be the most efficient for the page, as the animation could potentially continue running even when the loader is not visible.
Approaches I've Explored
I attempted to modify the animation so it only runs when the element has the visible
class applied. However, this resulted in a choppy effect because the animation halted immediately upon class removal, without allowing the loader to fade out smoothly. Additionally, incorporating a transition
into the animation did not yield any noticeable changes.