If I was going to refactor all of this animation code, I would put each step into its own function, so the the four lines above would not have to be repeated, and you could just call the function that represented the next step of the transition...  But for now, it is probably simplest to just repeat the code.

In the version below, I notice that a setTimeout() is necessary.  Do you need to add that here, or do you want to try removing it there?