Events

Learn the two approaches we can use to listen to CSS transition events.

CSS transitions emit events that we can listen to using JavaScript. There are some slight differences in how we attach event listeners between a non-Angular project and an Angular one. Let’s make a list of these events:

  • transitionrun: This is emitted when the transition is created (not started).

  • transitionstart: This is emitted when the transition starts.

  • transitionend: This is emitted when the transition completes.

  • transitioncancel: This is emitted when the transition is canceled.

Notice that the event names are all in lowercase and not camel case.

Press + to interact

How to use events?

To listen to these events, we’ll need to attach an event listener to the element with the transition using addEventListener. It’s a global event listener, not specific to just animations or transitions. We can then pass any of the events from the list of events above to listen to a specific one.

Approach one: using addEventListener

We can ...