Skip to content

[css-view-transitions-2] Syntax for customizing transitions based on their type #8960

Closed
@ydaniv

Description

@ydaniv

Currently in order to change the style of the generated pseudo-tree based on state of the DOM one has to use a :has() selector on the html element to capture that state and then chain the pseudo-elements from there to style them.
I have discussed this with @una, @lilles, and @andruud at CSS Day and they said that using a :has() on an element so high up the DOM tree may be a big perf issue with rendering possibly taking a few seconds in some cases.

Here is a codepen with a simple example: https://codepen.io/ydaniv/pen/QWJjgQp

Basically it has this:

<main>
  <div id=source></div>
  <div id=target></div>
</main>

And styles:

/* This is our source of trouble */
html:has(.switch)::view-transition-group(circle) {
  animation-duration: 1.2s;
}

#source {
  view-transition-name: circle;
 
 .switch & {
    display: none;
  }
}

#target {
  display: none;

  .switch & {
    display: block;
  }
}

And the JS for triggering VT is:

document.startViewTransition(() => {
    main.classList.toggle('switch');
});

My concern is that this may become a common pattern and cause big frustration, probably even more so users than to authors.

It's possible to work around this by lifting all such state up to the html element and try to mitigate this with communicating this to authors.
However, I think it's worth trying to find another solution for avoiding it altogetehr.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Thursday Afternoon

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions