Transition Events
JavaScript can listen for transitionstart, transitionend, and transitioncancel events to respond when transitions complete.
JavaScript can listen for transitionstart, transitionend, and transitioncancel events to respond when transitions complete.
const box = document.querySelector(".box");
box.addEventListener("transitionend", (e) => {
console.log(`${e.propertyName} transition finished`);
// Remove class after fade-out completes
if (e.propertyName === "opacity") {
box.style.display = "none";
}
});
// Trigger the transition
box.classList.add("fade-out");
transitionend fires once per animated property — check event.propertyName if multiple properties are transitioning.