<button id="btn">hover me</button>
html,
body {
  margin: 0;
  height: 100%;
  display: grid;
  place-content: center;
}
button {
  position: relative;
  font-size: 60px;
  border: 0;
  background-color: rgba(144, 41, 247, 0.515);
  padding: 0.5em 1em;
  color: #fff;
  border-radius: 0.2em;
  cursor: pointer;
  overflow: hidden;
}
button::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: #d573ff;
  z-index: -1;
  width: 0%;
}

button:hover::before {
  width: 100%;
  transition: width 2s;
}
btn.addEventListener("transitionend", (ev) => {
  alert("触发了");
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.