-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to dispose the animation after no longer needed? #196
Comments
The animation API has a cancel method. In your example, the "if" and "else" blocks look the same. Should the blocks be setting different keyframe options? If so, then rather than cancelling and restarting the animation, calling animation.effect.setKeyframes() is an option. |
@kevers-google The parameters are the same, however, the only change is in the CSS variable All I need is to re-initialize the animation when the direction is changed. So the |
Yes, animation.cancel() puts the animation into an idle state where it is no longer active. The animation will eventually be garbage collected provided there are no live references in JavaScript. Canceling and then recreating the animation will work, but could result in flicker in some cases since the animation is momentarily not in effect. You can start the new animation before cancelling the old one to avoid flicker since composite ordering will ensure that the new animation replaces the old one. The reason for cancelling the old animation in this case, is performance and memory (avoid stale animations piling up). An alternate approach is requestAnimationFrame(() => { In other words, you can replace the keyframes on the existing animation rather than creating a new animation. Long story short, you have options. If cancelling and creating a new animation works well enough for your application, then that might be simplest. If you encounter flicker problems when restarting the animation, then you can consider one of the other options. |
I have an option where I need to re-create the animation instance, how can I dispose the animation before creating a new one?
The text was updated successfully, but these errors were encountered: