diff --git a/src/content/docs/basics/styling.mdx b/src/content/docs/basics/styling.mdx index 51d4073..a40b007 100644 --- a/src/content/docs/basics/styling.mdx +++ b/src/content/docs/basics/styling.mdx @@ -244,6 +244,10 @@ Also seen above: You can address the root of all view transition pseudo-elements When you have CSS rules for a large number of view transition names, you can use the `(*)` pattern to address a pseudo-element for _all_ transition names and use specific rules with the (`(name-x)`) pattern to handle the exception. There might be situations where you wish for a better developer experience. This is where view transition classes come in. +:::note +This feature is available beginning with Level 2 of the View Transition API. +::: + Similar to the `view-transition-name` property, you can assign `view-transition-class` values to DOM elements. While view transition names have to be unique in the DOM, view transition class values need not and typically will not be unique. When looking at how the view transition classes are used, the similarity to CSS classes is rather obvious. You use them inside the pseudo-element selectors, prefixed by a dot (`.`). @@ -273,8 +277,23 @@ This might best be combined with dynamically (per script) added view transition Often you want to support different animations for a given view transition pseudo-element and select one of those alternatives depending on some condition. The concept that the View Transition API provides for this use case is called _active view transition types_. +:::note +This feature is available beginning with Level 2 of the View Transition API. +::: + While it is active, a view transition might have a set of identifiers called _types_ that can be used in CSS pseudo-classes to select different rules. During the view transition, the set can be altered at any time by assigning to the `types` property of the viewTransition object. The initial set of types can be set when calling `startViewTransition()` or it might be specified using the `types` property inside a `@view-transition` rule. +```ts title="Level 2 signature of startViewTranstion()" +document.startViewTransition({types: ['boom'], update: changeTheDOM}) +``` +or +```css title="Setting types using CSS" +@view-transition { + navigation: auto; + types: boom, var(--special) +} +``` + The pseudo-class that can check for types is `:active-view-transition-type()`. It takes a comma separated list of types. If at least one of these types is set on the active view transition, the pseudo-class matches the documents root element. Thus, the typical patterns to use `:active-view-transition-type()` are: diff --git a/src/content/docs/tips/css.mdx b/src/content/docs/tips/css.mdx index 3d2362e..a9af86c 100644 --- a/src/content/docs/tips/css.mdx +++ b/src/content/docs/tips/css.mdx @@ -21,13 +21,13 @@ The last chance to set these names on the old page using JavaScript is during th For the new images, your last opportunity to define names using JavaScript is the pagereveal event, triggered after the new page is loaded and just before screenshots of the new images are taken. ## Animations -This might come as a surprise, but it's simple to explain: Besides defining view transition names and taking screenshots of the old images, the old page has no control over how the view transition is styled. Any pseudo-element related CSS defined on the old page will be ignored, unless the old page is also the new one. +This might come as a surprise, but it's simple to explain: Besides defining view transition names and taking screenshots of the old images, the old page has no control over how the view transition is styled. Any pseudo-element related CSS defined on the old page will be ignored — unless the old page is also the new one. The reason for this is that the animations are triggered by the appearance of the view transition pseudo-elements on the `:root` element of the new page. At that moment, only the styles from the new page are available. -While it seems logical, it’s still somewhat counterintuitive that the CSS for an exit animation for an element that only exists on the old page needs to be defined on the new page. +While it seems logical, it’s still somewhat counterintuitive that the CSS for an exit animation for an element that only exists on the old page needs to be defined on the new page. But keep in mind, that it is not the old element that is animated, but the _image_ of the old element that has been inserted as a pseudo-element on the new page. -If you’re accustomed to building with components, it might not always be clear which page a component will end up on and where the corresponding CSS should be placed. Additionally, the requirement that view transition names must be unique on a page makes you reconsider whether it’s wise to hardcode view transition names inside reusable components. +If you're accustomed to building with components, it might not always be clear which page a component will end up on and where the corresponding CSS should be placed. Additionally, the requirement that view transition names must be unique on a page makes you reconsider whether it's wise to hardcode view transition names inside reusable components. But that is not much different from using `id` attributes. ## Conclusion I'm still exploring paths and alternatives but this would be my current recommendations: