Skip to content

Commit 872d337

Browse files
andruudfantasai
andauthored
[scroll-animations-1] Define scroll/view-timeline-attachment #7759
This is a squashed commit; PR discussion at #8680 and andruud#1 Co-authored-by: fantasai <fantasai.bugs@inkedblade.net>
1 parent fc7abaf commit 872d337

File tree

1 file changed

+242
-32
lines changed

1 file changed

+242
-32
lines changed

scroll-animations-1/Overview.bs

Lines changed: 242 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -317,79 +317,160 @@ spec: cssom-view-1; type: dfn;
317317
## Named Scroll Progress Timelines ## {#scroll-timelines-named}
318318

319319
[=Scroll progress timelines=] can also be defined on the [=scroll container=] itself,
320-
and then referenced by name.
321-
See [[#timeline-scope]].
320+
and then referenced by name
321+
by elements within the name’s scope
322+
(see [[#timeline-scope]]).
322323

323-
Named scroll progress timelines are declared in the [=coordinated value list=]
324+
Such <dfn>named scroll progress timelines</dfn>
325+
are declared in the [=coordinated value list=]
324326
constructed from the [=longhands=] of the 'scroll-timeline' [=shorthand property=],
325327
which form a [=coordinating list property group=]
326328
with 'scroll-timeline-name' as the [=coordinating list base property=].
327329
See [[css-values-4#linked-properties]].
328330

331+
Depending on its <dfn local-lt='attachment'>name attachment</dfn>
332+
('scroll-timeline-attachment'),
333+
a name specified by 'scroll-timeline-name'
334+
can be attached to a [=scroll progress timeline=] defined on the element’s own box
335+
(''scroll-timeline-attachment/local''),
336+
declared for the element’s scope but deferred
337+
to a descendant [=scroll container=]’s [=scroll progress timeline=]
338+
(''scroll-timeline-attachment/defer''),
339+
or used to attach the element’s [=scroll progress timeline=]
340+
to a name declared and deferred by an ancestor
341+
(''scroll-timeline-attachment/ancestor''),
342+
effectively allowing its [[#timeline-scope|scope]] to expand
343+
beyond this element and its descendants.
344+
329345
### Naming a Scroll Progress Timeline: the 'scroll-timeline-name' property ### {#scroll-timeline-name}
330346

331347
<pre class='propdef'>
332348
Name: scroll-timeline-name
333349
Value: none | <<custom-ident>>#
334350
Initial: none
335-
Applies to: [=scroll containers=]
351+
Applies to: all elements
336352
Inherited: no
337353
Computed value: the keyword ''scroll-timeline-name/none'' or a list of <<custom-ident>>s
338354
Animation type: not animatable
339355
</pre>
340356

341-
Specifies names for the [=scroll progress timelines=]
342-
associated with this [=scroll container=].
343-
The axis for this timeline is given by 'scroll-timeline-axis'.
357+
Specifies names for the [=named scroll progress timelines=]
358+
associated with this element.
359+
Depending on the name’s [=attachment=] ('view-timeline-attachment'),
360+
this element can declare a name,
361+
define its [=scroll progress timeline=],
362+
or both (the default).
344363

345364
### Axis of a Scroll Progress Timeline: the 'scroll-timeline-axis' property ### {#scroll-timeline-axis}
346365

347366
<pre class='propdef'>
348367
Name: scroll-timeline-axis
349368
Value: [ block | inline | vertical | horizontal ]#
350369
Initial: block
351-
Applies to: [=scroll containers=]
370+
Applies to: all elements
352371
Inherited: no
353372
Computed value: a list of the keywords specified
354373
Animation type: not animatable
355374
</pre>
356375

357-
Specifies an axis for each [=scroll progress timeline=]
358-
associated with this [=scroll container=].
359-
The name for this timeline is given by 'scroll-timeline-name'.
376+
Specifies the axis of any [=named scroll progress timelines=]
377+
sourced from this [=scroll container=].
378+
If this box is not a [=scroll container=],
379+
then the corresponding [=named scroll progress timeline=]
380+
is [=inactive timeline|inactive=].
360381

361382
Values are as defined for ''scroll()''.
362383

384+
Note: This property has no effect when combined
385+
with a 'scroll-timeline-attachment' of ''scroll-timeline-attachment/defer''.
386+
387+
### Attachment of a Scroll Progress Timeline: the 'scroll-timeline-attachment' property ### {#scroll-timeline-attachment}
388+
389+
<pre class='propdef'>
390+
Name: scroll-timeline-attachment
391+
Value: [ local | defer | ancestor ]#
392+
Initial: local
393+
Applies to: all elements
394+
Inherited: no
395+
Computed value: a list of the keywords specified
396+
Animation type: not animatable
397+
</pre>
398+
399+
Specifies the [=name attachment=]
400+
of each [=scroll progress timeline=] name
401+
specified by 'scroll-timeline-name'.
402+
403+
Values have the following meanings:
404+
405+
<dl dfn-type=value dfn-for=scroll-timeline-attachment>
406+
<dt><dfn>local</dfn>
407+
<dd>
408+
This [=scroll progress timeline=] name
409+
[=attaches=] to the corresponding [=scroll progress timeline=]
410+
defined on this box.
411+
412+
<dt><dfn>defer</dfn>
413+
<dd>
414+
This [=scroll progress timeline=] name’s [=attachment=]
415+
is deferred to its descendants.
416+
In other words,
417+
this element declares a [=scroll progress timeline=]’s name
418+
and defines its scope (see [[#timeline-scope]]),
419+
but defers the timeline’s definition
420+
([=scroll container=] source and axis)
421+
to its descendants.
422+
423+
If more than one matching descendant [=scroll progress timeline=] exists,
424+
or if no such timeline exists,
425+
then the timeline name has no [=attachment=],
426+
and represents an [=inactive timeline=].
427+
428+
ISSUE: Should it instead be ignored (be invisible to lookup)?
429+
(This might make it harder to implement.)
430+
If multiple, should it attach instead to the last declared timeline (in tree order)
431+
rather than invalidating the attachment?
432+
433+
<dt><dfn>ancestor</dfn>
434+
<dd>
435+
This [=scroll progress timeline=] definition,
436+
attaches to the closest matching [=scroll progress timeline=] name
437+
that was deferred (''scroll-timeline-name/defer'')
438+
by an ancestor (if any).
439+
440+
If no such ancestor exists,
441+
the [=attachment=] is treated as ''scroll-timeline-attachment/local''.
442+
</dl>
443+
363444
### Scroll Timeline Shorthand: the 'scroll-timeline' shorthand ### {#scroll-timeline-shorthand}
364445

365446
<pre class='propdef shorthand'>
366447
Name: scroll-timeline
367-
Value: [ <<'scroll-timeline-name'>> <<'scroll-timeline-axis'>>? ]#
368-
Applies to: [=scroll containers=]
448+
Value: [ <<'scroll-timeline-name'>> [ <<'scroll-timeline-axis'>> || <<'scroll-timeline-attachment'>> ]? ]#
449+
Applies to: all elements
369450
Inherited: no
370451
Animation type: not animatable
371452
</pre>
372453

373454
This property is a [=shorthand=] for setting
374-
'scroll-timeline-name' and 'scroll-timeline-axis'
455+
'scroll-timeline-name', 'scroll-timeline-axis', and 'scroll-timeline-attachment'
375456
in a single declaration.
376457

377458
# View Progress Timelines # {#view-timelines}
378459

379460
Often animations are desired to start and end
380461
during the portion of the [=scroll progress timeline=]
381-
that a particular element
382-
(the <dfn>view progress subject</dfn> element)
462+
that a particular box
463+
(the <dfn>view progress subject</dfn>)
383464
is in view within the [=scrollport=].
384465
<dfn export>View progress timelines</dfn>
385466
are segments of a [=scroll progress timeline=]
386467
that are scoped to the scroll positions
387-
in which any part of the associated element’s [=principal box=]
468+
in which any part of the subject element’s [=principal box=]
388469
intersects its nearest ancestor [=scrollport=]
389470
(or more precisely, the relevant [=view progress visibility range=]
390471
of that [=scrollport=]).
391-
The startmost such scroll position represents 0% progress
392-
and the endmost such scroll position represents 100% progress,
472+
The startmost such scroll position represents 0% progress,
473+
and the endmost such scroll position represents 100% progress;
393474
see [[#view-timeline-progress]].
394475

395476
Note: The 0% and 100% scroll positions are not always reachable,
@@ -649,15 +730,25 @@ spec: cssom-view-1; type: dfn;
649730
## Named View Progress Timelines ## {#view-timelines-named}
650731

651732
[=View progress timelines=] can also be defined declaratively
652-
and then referenced by name.
653-
See [[#timeline-scope]].
733+
and then referenced by name
734+
by elements within the name’s scope
735+
(see [[#timeline-scope]]).
654736

655-
Named view progress timelines are declared in the [=coordinated value list=]
737+
Such <dfn>named view progress timelines</dfn>
738+
are declared in the [=coordinated value list=]
656739
constructed from the 'view-timeline-*' properties,
657740
which form a [=coordinating list property group=]
658741
with 'view-timeline-name' as the [=coordinating list base property=].
659742
See [[css-values-4#linked-properties]].
660743

744+
[[#scroll-timelines-named|As for named scroll progress timelines]],
745+
[=named view progress timelines=] can have various [=name attachments=],
746+
allowing a name specified by 'view-timeline-name'
747+
to be attached to the box’s own [=view progress timeline=],
748+
deferring it to a descendant box’s [=view progress timeline=],
749+
or connecting the box’s [=view progress timeline=]
750+
to the scope of an ancestor.
751+
661752
### Naming a View Progress Timeline: the 'view-timeline-name' property ### {#view-timeline-name}
662753

663754
<pre class='propdef'>
@@ -670,8 +761,12 @@ spec: cssom-view-1; type: dfn;
670761
Animation type: not animatable
671762
</pre>
672763

673-
Specifies names for any [=view progress timelines=]
674-
associated with this element’s [=principal box=].
764+
Specifies names for the [=named view progress timelines=]
765+
associated with this element.
766+
Depending on the name’s [=attachment=] ('view-timeline-attachment'),
767+
this element can declare a name,
768+
define its [=view progress timeline=],
769+
or both (the default).
675770

676771
### Axis of a View Progress Timeline: the 'view-timeline-axis' property ### {#view-timeline-axis}
677772

@@ -685,8 +780,13 @@ spec: cssom-view-1; type: dfn;
685780
Animation type: not animatable
686781
</pre>
687782

688-
Specifies an axis for each named [=view progress timeline=]
689-
associated with this [=scroll container=].
783+
Specifies the axis of any [=named view progress timelines=]
784+
derived from this element’s [=principal box=].
785+
786+
Values are as defined for ''view()''.
787+
788+
Note: This property has no effect when combined
789+
with a 'view-timeline-attachment' of ''view-timeline-attachment/defer''.
690790

691791
### Inset of a View Progress Timeline: the 'view-timeline-inset' property ### {#view-timeline-inset}
692792

@@ -721,16 +821,74 @@ spec: cssom-view-1; type: dfn;
721821
defines an inward offset from the corresponding edge of the scrollport.
722822
</dl>
723823

824+
Note: This property has no effect when combined
825+
with a 'view-timeline-attachment' of ''view-timeline-attachment/defer''.
826+
827+
### Attachment of a View Progress Timeline: the 'view-timeline-attachment' property ### {#view-timeline-attachment}
828+
829+
<pre class='propdef'>
830+
Name: view-timeline-attachment
831+
Value: [ local | defer | ancestor ]#
832+
Initial: local
833+
Applies to: all elements
834+
Inherited: no
835+
Computed value: a list of the keywords specified
836+
Animation type: not animatable
837+
</pre>
838+
839+
Specifies the [=name attachment=]
840+
of each [=view progress timeline=] name
841+
specified by 'view-timeline-name'.
842+
843+
Values have the following meanings:
844+
845+
<dl dfn-type=value dfn-for=view-timeline-attachment>
846+
<dt><dfn>local</dfn>
847+
<dd>
848+
This [=view progress timeline=] name
849+
[=attaches=] to the corresponding [=view progress timeline=]
850+
defined on this box.
851+
852+
<dt><dfn>defer</dfn>
853+
<dd>
854+
This [=view progress timeline=] name’s [=attachment=]
855+
is deferred to its descendants.
856+
In other words,
857+
this element declares a [=view progress timeline=]’s name
858+
and defines its scope (see [[#timeline-scope]]),
859+
but defers the timeline’s definition
860+
([=view progress subject|subject=],
861+
[=scroll container=] source,
862+
axis, and
863+
[=view progress visibility range|visibility range=])
864+
to its descendants.
865+
866+
If more than one matching descendant [=view progress timeline=] exists,
867+
or if no such timeline exists,
868+
then this timeline name has no [=attachment=],
869+
and represents an [=inactive timeline=].
870+
871+
<dt><dfn>ancestor</dfn>
872+
<dd>
873+
This [=view progress timeline=] definition
874+
[=attaches=] to the closest matching [=view progress timeline=] name
875+
that was deferred (''view-timeline-name/defer'')
876+
by an ancestor (if any).
877+
878+
If no such ancestor exists,
879+
the [=attachment=] is treated as ''view-timeline-attachment/local''.
880+
</dl>
881+
724882
### View Timeline Shorthand: the 'view-timeline' shorthand ### {#view-timeline-shorthand}
725883

726884
<pre class='propdef shorthand'>
727885
Name: view-timeline
728-
Value: [ <<'view-timeline-name'>> <<'view-timeline-axis'>>? ]#
886+
Value: [ <<'view-timeline-name'>> [ <<'view-timeline-axis'>> || <<'view-timeline-attachment'>> ]? ]#
729887
Applies to: all elements
730888
</pre>
731889

732890
This property is a [=shorthand=] for setting
733-
'view-timeline-name' and 'view-timeline-axis'
891+
'view-timeline-name', 'view-timeline-axis', and 'view-timeline-attachment'
734892
in a single declaration.
735893
It does not set 'view-timeline-inset'.
736894

@@ -789,20 +947,72 @@ spec: cssom-view-1; type: dfn;
789947
The editors would be interested in hearing about
790948
any real use cases for multiple iterations here.
791949

792-
## Named Timeline Scoping ## {#timeline-scope}
950+
## Named Timeline Scoping and Lookup ## {#timeline-scope}
793951

794952
A named [=scroll progress timeline=] or [=view progress timeline=]
795-
is referenceable in 'animation-timeline' by:
796-
* the declaring element itself
953+
is referenceable by:
954+
* the name-declaring element itself
797955
* that element’s descendants
798956

799957
If multiple elements have declared the same timeline name,
800958
the matching timeline is the one declared
801959
on the nearest element in tree order.
802960
In case of a name conflict on the same element,
961+
names declared later in the naming property
962+
('scroll-timeline-name', 'view-timeline-name')
963+
take precedence, and
803964
[=scroll progress timelines=] take precedence over [=view progress timelines=].
804965

805-
ISSUE(7759): We plan to add functionality to expand the scope.
966+
Note: Although only names on the ancestor chain
967+
are visible to a timeline name lookup,
968+
a deferred [=name attachment=] allows a name declared on an ancestor
969+
to be attached to a timeline sourced elsewhere in its subtree,
970+
effectively allowing lookup of a timeline sourced
971+
from a sibling, cousin, or descendant.
972+
See 'scroll-timeline-attachment'/'view-timeline-attachment'.
973+
974+
<div class=example>
975+
Using ''scroll-timeline-attachment: defer'',
976+
an element can refer to timelines
977+
bound to elements that are siblings, cousins, or even descendants.
978+
For example, the following creates an animation on an element
979+
that is linked to a [=scroll progress timeline=]
980+
defined by the subsequent sibling.
981+
982+
<xmp highlight=html>
983+
<style>
984+
@keyframes anim {
985+
from { color: red; }
986+
to { color: green; }
987+
}
988+
989+
.root {
990+
scroll-timeline: scroller defer;
991+
}
992+
993+
.root .animation {
994+
animation: anim;
995+
animation-timeline: scroller;
996+
}
997+
998+
.root .animation + .scroller {
999+
scroll-timeline: scroller ancestor;
1000+
}
1001+
</style>
1002+
&hellip;
1003+
<section class="root">
1004+
<div class="animation">Animating Box</div>
1005+
<div class="scroller">Scrollable Box</div>
1006+
</section>
1007+
</xmp>
1008+
</div>
1009+
1010+
If a timeline name has been declared,
1011+
but does not have a usable [=attachment=]
1012+
(e.g. if it is declared with ''scroll-timeline-name/defer'',
1013+
but no [=scroll progress timeline=] or [=view progress timeline=]
1014+
is [=attachment|attached=] to it),
1015+
it refers to an [=inactive timeline=].
8061016

8071017
## Animation Events ## {#events}
8081018

0 commit comments

Comments
 (0)