Skip to content

Commit 850a2cd

Browse files
committed
[css-view-transitions-2] Add 'view-transition-class'
A `view-transition-class` property allows specifying view-transition pseudo-elements that apply to multiple participating elements without having to replicate them. In this PR: - Specifying `view-transition-class` - Extending the pseudo-element syntax to support `::view-transition-foo(name.class)` - Extending the capture algorithms and data structure to capture the classes - Added a simple example for using classes Based on [this resolution](w3c#8319 (comment)). Closes w3c#8319
1 parent 2212352 commit 850a2cd

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed

css-view-transitions-1/Overview.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
11671167

11681168
### [=Captured elements=] ### {#captured-elements}
11691169

1170-
A <dfn>captured element</dfn> is a [=struct=] with the following:
1170+
A <dfn export>captured element</dfn> is a [=struct=] with the following:
11711171

11721172
<dl dfn-for="captured element">
11731173
: <dfn>old image</dfn>

css-view-transitions-2/Overview.bs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ spec:css-view-transitions-1;
3535
text: setup view transition; type: dfn;
3636
spec:dom; type:dfn; text:document
3737
spec:css22; type:dfn; text:element
38+
spec:selectors-4; type:dfn;
39+
text:selector
40+
text:type selector
3841
spec:html
3942
text: latest entry; type: dfn;
4043
text: was created via cross-origin redirects; type: dfn;
@@ -206,6 +209,83 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
206209
```
207210
</div>
208211

212+
### Example of using 'view-transition-class' ### {#vt-class-example}
213+
214+
In addition to cross-document view-transitions, this document specifies a way to use the same view-transition style
215+
for multiple elements without having to replicate the corresponding pseudo-elements.
216+
217+
<div class="example">
218+
This example creates a transition with each box participating under its own name, while applying
219+
a 1-second duration to the animation of all the boxes:
220+
221+
```html
222+
<div class="box" id="red-box"></div>
223+
<div class="box" id="green-box"></div>
224+
<div class="box" id="yellow-box"></div>
225+
```
226+
227+
```css
228+
div.box {
229+
view-transition-class: any-box;
230+
width: 100px;
231+
height: 100px;
232+
}
233+
#red-box {
234+
view-transition-name: red-box;
235+
background: red;
236+
}
237+
#green-box {
238+
view-transition-name: green-box;
239+
background: green;
240+
}
241+
#yellow-box {
242+
view-transition-name: yellow-box;
243+
background: yellow;
244+
}
245+
246+
/* The following style would apply to all the boxes, thanks to 'view-transition-class' */
247+
::view-transition-group(*.any-box) {
248+
animation-duration: 1s;
249+
}
250+
```
251+
252+
</div>
253+
254+
255+
# CSS Properties # {#css-properties}
256+
257+
## Applying the same style to multiple participating elements: the 'view-transition-class' property ## {#view-transition-class-prop}
258+
259+
<pre class=propdef>
260+
Name: view-transition-class
261+
Value: none | <<custom-ident>>*
262+
Initial: none
263+
Inherited: no
264+
Percentages: n/a
265+
Computed Value: as specified
266+
Animation type: discrete
267+
</pre>
268+
269+
The 'view-transition-class' works alongside 'view-transition-name', and is read at the same time
270+
'view-transition-name' is read. But unlike 'view-transition-name', 'view-transition-class' doesn't
271+
have to be unique - an element can have several view-transition classes, and the same 'view-transition-class'
272+
can apply to multiple elements. While 'view-transition-name' is used to match between the element
273+
in the old state with its corresponding element in the new state, 'view-transition-class' is used
274+
only to apply styles using the view-transition pseudo-elements
275+
(''::view-transition-group()'', ''::view-transition-image-pair()'', ''::view-transition-old()'', ''::view-transition-new()'').
276+
277+
<dl dfn-type=value dfn-for=view-transition-class>
278+
: <dfn>none</dfn>
279+
:: No class would apply to the [=/element=], and pseudo-elements would have to match its 'view-transition-name'.
280+
281+
: <dfn><<custom-ident>>*</dfn>
282+
:: All of the specified <<custom-ident>> values (apart from <css>none</css>) apply as classes for the [=/element=].
283+
284+
Note: If the same 'view-transition-name' is specified for an element both in the old and new states of the transition,
285+
only the 'view-transition-class' values from the new state apply. This also applies for cross-document view-transitions:
286+
classes from the old document would only apply if their corresponding 'view-transition-name' was not specified in the new document.
287+
</dl>
288+
209289
# Pseudo-classes # {#pseudo-classes}
210290

211291
## Active View Transition Pseudo-class '':active-view-transition()''' ## {#the-active-view-transition-pseudo}
@@ -259,6 +339,34 @@ document.startViewTransition({update: updateTheDOMSomehow});
259339
```
260340
</div>
261341

342+
# Additions to view-transition pseudo-elements # {#pseudo-element-additions}
343+
344+
The <dfn>named view transition pseudo-elements</dfn>
345+
(''view-transition-group()'', ''view-transition-image-pair()'', ''view-transition-old()'', ''view-transition-new()'')
346+
are extended to support the following syntax for each |pseudo|:
347+
348+
<pre class=prod>
349+
::view-transition-group(<<pt-name-selector>><<pt-class-selector>>)
350+
::view-transition-image-pair(<<pt-name-selector>><<pt-class-selector>>)
351+
::view-transition-old(<<pt-name-selector>><<pt-class-selector>>)
352+
::view-transition-new(<<pt-name-selector>><<pt-class-selector>>)
353+
</pre>
354+
355+
where <<pt-name-selector>> works as previously defined, and
356+
<<pt-class-selector>> has the following syntax definition:
357+
358+
<pre class=prod>
359+
<dfn>&lt;pt-class-selector></dfn> = ('.' <<custom-ident>>)*
360+
</pre>
361+
362+
A [=named view transition pseudo-element=] [=selector=] which has one or more <<custom-ident>> values
363+
in its <<pt-class-selector>> would only match an element if the element's [=captured element/class list=]
364+
[=list/contains=] all of those values.
365+
366+
The specificity of a [=named view transition pseudo-element=] [=selector=]
367+
with a <<pt-class-selector>>
368+
is equivalent to a [=class selector=] with the equivalent number of classes.
369+
262370
# CSS rules # {#css-rules}
263371

264372
## The <dfn id="at-view-transition-rule">''@view-transition''</dfn> rule ## {#view-transition-rule}
@@ -386,6 +494,27 @@ The {{CSSViewTransitionRule}} represents a ''@view-transition'' rule.
386494
:: Null or a [=list=] of strings, initially null.
387495
</dl>
388496

497+
## Additions to [=captured element=] struct ## {#additions-to-captured-element-struct}
498+
499+
<dl>
500+
: <dfn for="captured element">class list</dfn>
501+
:: a [=/list=] of strings, initially empty.
502+
</dl>
503+
504+
## Additions to capture algorithms: ## {#additions-to-capture-algorithms}
505+
<div algorithm="capture old classes">
506+
When capturing the old state of the view transition, perform the following step when iterating on |captureElements| given |element| and |capture|:
507+
508+
1. Set |capture|'s [=captured element/class list=] to the [=computed value=] of |element|'s 'view-transition-class'.
509+
510+
</div>
511+
512+
<div algorithm="capture new classes">
513+
When capturing the new state of the view transition, perform the following step when iterating on |captureElements| given |element| and |namedElements|:
514+
515+
1. Set |namedElement|[|transitionName|]'s [=captured element/class list=] to the [=computed value=] of |element|'s 'view-transition-class'.
516+
</div>
517+
389518
## Monkey patches to HTML ## {#monkey-patch-to-html}
390519

391520
<div algorithm="monkey patch to apply the history step">

0 commit comments

Comments
 (0)