Skip to content

Commit d59c114

Browse files
authored
[scroll-animations-1] Add auto duration and animation ranges to explainer (#8763)
This adds sections explaining the addition of automatically fitting an auto duration to a scroll timeline or view timeline and the introduction of a ranges section to explain animation ranges.
1 parent c32bba3 commit d59c114

File tree

1 file changed

+77
-17
lines changed

1 file changed

+77
-17
lines changed

scroll-animations-1/EXPLAINER.md

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,83 @@ controlled, and inspected with existing methods.
355355

356356
Some of the complexities that come from this decision are:
357357

358-
* **Time vs Scroll Offset**: The concept of **time value** (exposed in
359-
Milliseconds units) were central to the Web Animation model. Adding
360-
ScrollTimeline requires updating the animation timing model to allow
361-
for other unit types. We decided to go with percentages as they had a
362-
clean direct mapping to animation progress (which is already a proportion).
363-
364-
* **Exclusive end ranges**: In Web Animations, ranges have exclusive ends to
365-
help make it easier to use overlapping ranges such as putting multiple
366-
animations in a sequence. ScrollTimeline scroll range also has exclusive ends
367-
to match this. However this is problematic for a common case where scroll
368-
range is full size. Our solution was to [special
369-
case](https://github.com/w3c/csswg-drafts/issues/5223) this one.
370-
371-
* **Dynamic Scrollability**: It is possible for a scroller to no longer
372-
overflow (`overflow: auto`). We mapped this to the web animations model
373-
by having the timeline become idle in these situations where a time cannot
374-
be worked out.
358+
#### Time vs Scroll Offset
359+
360+
The concept of **time value** (exposed in
361+
Milliseconds units) were central to the Web Animation model. Adding
362+
ScrollTimeline requires updating the animation timing model to allow
363+
for other unit types. We decided to go with percentages as they had a
364+
clean direct mapping to animation progress (which is already a proportion).
365+
366+
#### Duration
367+
368+
Typically the duration of a scroll driven animation fills the range available for it.
369+
As such, web-animations-2
370+
adds an [intrinsic iteration duration](https://drafts.csswg.org/web-animations-2/#intrinsic-iteration-duration)
371+
for the default "auto" [duration](https://drafts.csswg.org/web-animations-1/#dom-effecttiming-duration) of web animations
372+
which fills the timeline range.
373+
374+
For CSS animations,
375+
["auto"](https://drafts.csswg.org/css-animations-2/#valdef-animation-duration-auto) is added as the initial value to match web animations.
376+
This does not change the implicit duration of 0s when run on a document timeline,
377+
but makes CSS animations implicitly fill their scroll or view timeline range,
378+
and allows future [group effects](https://drafts.csswg.org/web-animations-2/#group-effect) to intrinsically compute their duration.
379+
380+
This makes it so that either the following web animations:
381+
```js
382+
element.animate({transform: ['none', 'translateY(-100px)']}, timeline: new ScrollTimeline());
383+
```
384+
385+
Or the following CSS animation:
386+
```css
387+
.animate {
388+
animation: keyframes;
389+
animation-timeline: scroll();
390+
}
391+
```
392+
393+
Fit the animation to the full scroll range without the developer needing to specify a duration.
394+
395+
#### Animation range
396+
397+
Often authors will write effects which aren't meant to fill the timeline range.
398+
This spec adds the concept of a [timeline attachment range](https://drafts.csswg.org/scroll-animations-1/#named-range-animation-declaration) to animations.
399+
This defines when the animation starts,
400+
and the range which the above "auto" intrinsic iteration duration fills.
401+
402+
For example, given the following CSS:
403+
```css
404+
.animate {
405+
animation: keyframes;
406+
animation-range: enter;
407+
animation-timeline: view();
408+
}
409+
```
410+
411+
The animation's start time will be implicitly set to the start of the enter timeline range,
412+
and the animation's "auto" duration will intrinsically resolve to the length of the enter timeline range.
413+
414+
#### Exclusive end range exception
415+
416+
In Web Animations,
417+
ranges have exclusive ends
418+
to help make it easier to use overlapping ranges
419+
such as putting multiple animations in a sequence.
420+
421+
An exception is made when a scroll or view timeline
422+
is at its [progress timeline boundary](https://www.w3.org/TR/web-animations-2/#at-progress-timeline-boundary)
423+
(i.e. with an active range that fills the scroll range)
424+
to avoid the effect from becoming inactive at the scroll boundary.
425+
Since the user is unable to scroll past the boundary
426+
no special accommodation is needed
427+
to facilitate animations following the boundary.
428+
429+
#### Dynamic Scrollability
430+
431+
It is possible for a scroller to no longer
432+
overflow (`overflow: auto`). We mapped this to the web animations model
433+
by having the timeline become idle in these situations where a time cannot
434+
be worked out.
375435

376436
### Avoiding Layout Cycle
377437

0 commit comments

Comments
 (0)