element.addEventListener("transitionstart", () => {
console.log("Started transitioning");
});Element: transitionstart event / notebook
Element: transitionstart event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
element.ontransitionstart = () => {
console.log("Started transitioning");
};<div class="transition">Hover over me</div>
<div class="message"></div>.transition {
width: 100px;
height: 100px;
background: red;
transition-property: transform, background;
transition-duration: 2s;
transition-delay: 1s;
}
.transition:hover {
transform: rotate(90deg);
background: transparent;
}const transition = document.querySelector(".transition");
const message = document.querySelector(".message");
transition.addEventListener("transitionrun", () => {
message.textContent = "transitionrun fired";
});
transition.addEventListener("transitionstart", () => {
message.textContent = "transitionstart fired";
});
transition.addEventListener("transitionend", () => {
message.textContent = "transitionend fired";
});