First of all you need to have a css class that does the animation. You already mentioned that.
Second step is to have two buttons with different visibility. If you click on the button it executes some action that results in the button beeing invisible and the other to be visible (and the other way around. The easiest solution is by just using a boolean but it can also be based on a more complex expression).
The button that gets visible when clicking on the other one needs the class with the animation. The moment it becomes visible, the animation is executed.
The result is, that if you click on button a it disappears and button b appears with the animation.
Here is a quick and dirty test project that shows you what I mean. It is using animate css (https://animate.style/)
https://drive.google.com/file/d/1yQ1as-YEzS-Qib5SXtT4MuU5QGngZNHX/view?usp=sharing