transitionend Reports Which Property Finished
Each transitioned property fires its own transitionend carrying propertyName and elapsedTime, while an interrupted transition fires transitioncancel instead.
Code
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 —
documentwill 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
DOM Event Propagation VisualizerVisualize DOM event capturing, targeting, and bubbling phases in real time. Toggle stopPropagation and stopImmediatePropagation to see how events traverse the tree.HTTP Retry & Backoff CalculatorSimulate exponential backoff retry schedules with Full, Equal, Decorrelated, or No Jitter to inspect per-attempt wait times and cumulative latency.
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.
Report a problem with this exampleOpens a pre-filled issue on GitHub.