dankobgd
dankobgd

Reputation: 416

How do I cancel active view transition?

There is skipTransition() method but how am i even supposed to call it since page is not interactive by design. So to skip active transition i have to actually do something which i cannot?

const el = document.querySelector("div");
const btn = document.querySelector("button");
let vt;

el.onclick = () => {
  vt = document.startViewTransition(() => {
    el.style.left = "500px";
  });
};

btn.onclick = () => {
  console.log("btn clicked");
  vt?.skipTransition?.();
};
div {
  position: absolute;
  background-color: peru;
  top: 50px;
  left: 0;
  width: 100px;
  height: 100px;
  view-transition-name: box;
}

::view-transition-group(*) {
  animation-duration: 5000ms;
}
<div></div>
<button>stop</button>

Upvotes: 1

Views: 56

Answers (0)

Related Questions