event

Transitioncancel — CSS reference

Fires when a transition is canceled before normal completion. The event identifies the transitioned property. Do not assume a transition always runs, especially if a reduced-motion stylesheet disables it.

Formal Syntax & Structure

css syntaxcss
element.addEventListener("transitioncancel", handler);

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>transitioncancel</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}#a{width:100px;height:60px;opacity:0.2;background:#2855ac;color:white;padding:0;transition:opacity 1000ms linear}#a.active{opacity:1;width:200px}#a{transition-duration:100ms}</style><body><button id="toggle" type="button">Toggle panel</button><div id="a">Panel</div><script>const a=document.querySelector("#a");const toggle=document.querySelector("#toggle");toggle.onclick=()=>a.classList.toggle("active");function start(){getComputedStyle(a).opacity;getComputedStyle(a).width;toggle.click();getComputedStyle(a).opacity;getComputedStyle(a).width;return a.getAnimations()}async function sample(t,p="opacity"){const anim=start().find(x=>x.transitionProperty===p);if(!anim)return null;anim.pause();await anim.ready;anim.currentTime=t;return getComputedStyle(a).getPropertyValue(p)}const status=document.createElement("output");document.body.append(status);a.addEventListener("transitioncancel",e=>status.textContent=e.type+": "+e.propertyName);</script></body></html>
CSS Reference