transitionend Reports Which Property Finished

Each transitioned property fires its own transitionend carrying propertyName and elapsedTime, while an interrupted transition fires transitioncancel instead.

JavascriptResilience

Code

javascriptsnippet
14 lines
const panel = document.querySelector('#panel');

// each property participating in the transition fires its own transitionend when it finishes
panel.addEventListener('transitionend', (event) => {
  console.log('ended:', event.propertyName, 'after', event.elapsedTime, 's');
});

// an interrupted transition (e.g. the class is removed midway) fires transitioncancel, and no end event follows
panel.addEventListener('transitioncancel', (event) => {
  console.log('cancelled:', event.propertyName);
});

// triggering the transition: add a class that changes width/opacity (a matching CSS transition definition is required)
panel.classList.add('open');

What the code does

Top-level bindings panel hold the demo state — nothing sits inside a function scope.

What to watch for

  • No packages pulled in; the language’s built-in APIs carry all of the work here.
  • This is browser-side code — document will not resolve in Node.

Applying it

The run emits 2 labeled sections — ended:, cancelled: — one per step.

Statements that matter most here

panel.addEventListener('transitioncancel', (event) => {
  console.log('cancelled:', event.propertyName);
});
panel.addEventListener('transitionend', (event) => {
  console.log('ended:', event.propertyName, 'after', event.elapsedTime, 's');
});

Interactive Tools for This Topic

FAQ

Does transitionend Reports Which Property Finished run in plain Node.js?
No — it touches `document`, which exist only in the browser. Run it in a page (or the DevTools console) instead of a bare Node process.