In https://codepen.io/bramus/pen/JoKMaEd/5b12099cd1f907ac44d63e13a0aacce1 I am animating the ::view-transition-group(box) pseudo using the Web Animations API instead of using CSS.
The code is as follows:
::view-transition-group(box) {
animation-name: none;
}
document.addEventListener('click', async (e) => {
const t = document.startViewTransition(() => {});
await t.ready;
document.documentElement.animate(
{
translate: [
`0px 0px`,
`100px 0px`,
],
},
{
duration: 1000,
easing: 'ease',
pseudoElement: '::view-transition-group(box)',
}
);
});
What caught me off guard here is that when an ongoing view transition gets interrupted, the animations keep on existing. You can do that in the demo by doing consecutive clicks.
My expectation here would be that whenever a new View Transition gets started, the (WAAPI) animations added to the pseudos of the previous View Transition would be cleared as well, as it is a different View Transition (and the view-transition-name could be set on a totally different element).
I talked to @emilio about this, and this apparently is the general way how pseudos work because the originating element of those pseudos remains the same. Perhaps for View Transitions we need to change this behavior and anchor things on the VT instance instead of the originating element? I.e. this would clear the WAAPI-created animations when a different VT starts.