Maybe it is better to control the animation with extra attributes. The Onclick function activates two calls : One to set the state, the other to animate: