Fixing the Exit Transition

The exit transition can be animated by overriding the default behavior of the join() method.

We are going to animate the bars when they are leaving the document. We’ve already discussed why this is happening. In summary, the bars are removed before the transition is applied. Therefore, D3 will not animate the elements.

Transitioning the exit selection

We can fix this issue by overriding the default behavior in the join() function. In our script, we are passing in a function to the join() function. This function will run during the enter selection. This time around, we are interested in running a function during the exit selection. We will need to pass in another two arrow functions.

Get hands-on with 1200+ tech skills courses.