1. Introduction
This specification defines mechanisms for driving the progress of an animation based on the scroll progress of a scroll container. These scroll-driven animations use a timeline based on scroll position, rather than one based on clock time. This module provides both an imperative API building on the Web Animations API as well as a declarative API building on CSS Animations. [WEB-ANIMATIONS-1]
There are two types of scroll-driven timelines:
-
Scroll Progress Timelines, which are linked to the scroll progress of a particular scroll container
-
View Progress Timelines, which are linked to the view progress of a particular box through a scrollport
Note: Scroll-driven animations, whose progress is linked to the scroll position, are distinct from scroll-triggered animations, which are triggered by a scroll position, but whose progress is driven by time.
1.1. Relationship to other specifications
Web Animations [WEB-ANIMATIONS-1] defines an abstract conceptual model for animations on the Web platform, with elements of the model including animations and their timelines, and associated programming interfaces. This specification extends the Web Animations model by defining scroll-driven timelines and allowing them to drive progress in animations to create scroll-driven animations.
This specification introduces both programming interfaces for interacting with these concepts, as well as CSS properties that apply these concepts to CSS Animations [CSS-ANIMATIONS-1]. To the extent the behavior of these CSS properties is described in terms of the programming interfaces, User Agents that do not support scripting may still conform to this specification by implementing the CSS features to behave as if the underlying programming interfaces were in place.
Like most operations in CSS besides selector matching, features in this specification operate over the flattened element tree.
1.2. Relationship to asynchronous scrolling
Some user agents support scrolling that is asynchronous with respect to layout or script. This specification is intended to be compatible with such an architecture.
Specifically, this specification allows expressing scroll-driven effects in a way that does not require script to run each time the effect is sampled. User agents that support asynchronous scrolling are allowed (but not required) to sample such effects asynchronously as well.
1.3. Value Definitions
This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.
2. Scroll Progress Timelines
Scroll progress timelines are timelines linked to progress in the scroll position of a scroll container along a particular axis. The startmost scroll position represents 0% progress and the endmost scroll position represents 100% progress.
Scroll progress timelines can be referenced in animation-timeline anonymously using the scroll() functional notation or by name (see § 4.2 Named Timeline Scoping)
after declaring them using the scroll-timeline properties.
In the Web Animations API,
they can be represented anonymously by a ScrollTimeline
object.
2.1. Calculating Progress for a Scroll Progress Timeline
Progress (the current time) for a scroll progress timeline is calculated as: scroll offset ÷ (scrollable overflow size − scroll container size)
If the 0% position and 100% position coincide (i.e. the denominator in the current time formula is zero), the timeline is inactive.
2.2. Anonymous Scroll Progress Timelines
2.2.1. The scroll() notation
The scroll() functional notation can be used as a <single-animation-timeline> value in animation-timeline and specifies a scroll progress timeline. Its syntax is
<scroll()> = scroll( [ <scroller> || <axis> ]? ) <axis> = block | inline | vertical | horizontal <scroller> = root | nearest | self
By default, scroll() references the block axis of the nearest ancestor scroll container. Its arguments modify this lookup as follows:
- block
- Specifies to use the measure of progress along the block axis of the scroll container. (Default.)
- inline
- Specifies to use the measure of progress along the inline axis of the scroll container.
- vertical
- Specifies to use the measure of progress along the vertical axis of the scroll container.
- horizontal
- Specifies to use the measure of progress along the horizontal axis of the scroll container.
- nearest
- Specifies to use the nearest ancestor scroll container. (Default.)
- root
- Specifies to use the document viewport as the scroll container.
- self
- Specifies to use the element’s own principal box as the scroll container. If the principal box is not a scroll container, then the scroll progress timeline is inactive.
Each use of scroll() corresponds to its own instance of ScrollTimeline
in the Web Animations API,
even if multiple elements use scroll() to refer
to the same scroll container with the same arguments.
2.2.2. The ScrollTimeline
Interface
enum {
ScrollAxis ,
"block" ,
"inline" ,
"horizontal" };
"vertical" dictionary {
ScrollTimelineOptions Element ?;
source ScrollAxis = "block"; }; [
axis Exposed =Window ]interface :
ScrollTimeline AnimationTimeline {constructor (optional ScrollTimelineOptions = {});
options readonly attribute Element ?source ;readonly attribute ScrollAxis axis ; };
A ScrollTimeline
is an AnimationTimeline
that represents a scroll progress timeline.
It can be passed to
the Animation
constructor or the animate()
method
to link the animation to a scroll progress timeline.
source
, of type Element, readonly, nullable-
The scroll container element whose scroll position drives the progress of the timeline.
axis
, of type ScrollAxis, readonly-
The axis of scrolling that drives the progress of the timeline. See value definitions for <axis>, above.
Inherited attributes:
currentTime
(inherited fromAnimationTimeline
)-
Represents the scroll progress of the scroll container as a percentage CSSUnitValue, with 0% representing its startmost scroll position (in the writing mode of the scroll container). Null when the timeline is inactive.
While 0% will usually represent the scroll container’s initial scroll position, it might not depending on its content distribution. See CSS Box Alignment 3 § 5.3 Overflow and Scroll Positions. Is this what we want?
Add a note about whether currentTime
can be negative or > 100%.
ScrollTimeline(options)
-
Creates a new
ScrollTimeline
object using the following procedure:-
Let timeline be the new
ScrollTimeline
object. -
Set the
source
of timeline to:- If the
source
member of options is present and not null, -
The
source
member of options. - Otherwise,
-
The
scrollingElement
of theDocument
associated with theWindow
that is the current global object.
- If the
-
Set the
axis
property of timeline to the corresponding value from options.
-
If the source
of a ScrollTimeline
is an element whose principal box does not exist
or is not a scroll container,
or if there is no scrollable overflow,
then the ScrollTimeline
is inactive.
A ScrollTimeline
’s duration
is 100%.
The values of source
and currentTime
are both computed when either is requested or updated.
2.3. Named Scroll Progress Timelines
Scroll progress timelines can also be defined on the scroll container itself, and then referenced by name. See § 4.2 Named Timeline Scoping.
Named scroll progress timelines are declared in the coordinated value list constructed from the longhands of the scroll-timeline shorthand property, which form a coordinating list property group with scroll-timeline-name as the coordinating list base property. See CSS Values 4 § A Coordinating List-Valued Properties.
2.3.1. Naming a Scroll Progress Timeline: the scroll-timeline-name property
Name: | scroll-timeline-name |
---|---|
Value: | none | <custom-ident># |
Initial: | none |
Applies to: | scroll containers |
Inherited: | no |
Percentages: | n/a |
Computed value: | the keyword none or a list of <custom-ident>s |
Canonical order: | per grammar |
Animation type: | not animatable |
Specifies names for the scroll progress timelines associated with this scroll container. The axis for this timeline is given by scroll-timeline-axis.
2.3.2. Axis of a Scroll Progress Timeline: the scroll-timeline-axis property
Name: | scroll-timeline-axis |
---|---|
Value: | [ block | inline | vertical | horizontal ]# |
Initial: | block |
Applies to: | scroll containers |
Inherited: | no |
Percentages: | n/a |
Computed value: | a list of the keywords specified |
Canonical order: | per grammar |
Animation type: | not animatable |
Specifies an axis for each scroll progress timeline associated with this scroll container. The name for this timeline is given by scroll-timeline-name.
Values are as defined for scroll().
2.3.3. Scroll Timeline Shorthand: the scroll-timeline shorthand
Name: | scroll-timeline |
---|---|
Value: | [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]# |
Initial: | see individual properties |
Applies to: | scroll containers |
Inherited: | no |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | not animatable |
Canonical order: | per grammar |
This property is a shorthand for setting scroll-timeline-name and scroll-timeline-axis in a single declaration.
3. View Progress Timelines
Often animations are desired to start and end during the portion of the scroll progress timeline that a particular element (the view progress subject element) is in view within the scrollport. View progress timelines are segments of a scroll progress timeline that are scoped to the scroll positions in which any part of the associated element’s principal box intersects its nearest ancestor scrollport (or more precisely, the relevant view progress visibility range of that scrollport). The startmost such scroll position represents 0% progress and the endmost such scroll position represents 100% progress, see § 3.2 Calculating Progress for a View Progress Timeline.
Note: The 0% and 100% scroll positions are not always reachable, e.g. if the box is positioned at the start edge of the scrollable overflow rectangle, it might not be possible to scroll to < 32% progress.
View progress timelines can be referenced
anonymously using the view() functional notation or by name (see § 4.2 Named Timeline Scoping)
after declaring them using the view-timeline properties
on the view progress subject.
In the Web Animations API,
they can be represented anonymously by a ViewTimeline
object.
3.1. View Progress Timeline Ranges
View progress timelines define the following named timeline ranges:
- cover
-
Represents the full range of the view progress timeline:
-
0% progress represents the position at which the start border edge of the element’s principal box coincides with the end edge of its view progress visibility range.
-
100% progress represents the position at which the end border edge of the element’s principal box coincides with the start edge of its view progress visibility range.
-
- contain
-
Represents the range during which the principal box is either fully contained by, or fully covers,
its view progress visibility range within the scrollport.
-
0% progress represents the earlier position at which:
-
the start border edge of the element’s principal box coincides with the start edge of its view progress visibility range.
-
the end border edge of the element’s principal box coincides with the end edge of its view progress visibility range.
-
-
100% progress represents the later position at which:
-
the start border edge of the element’s principal box coincides with the start edge of its view progress visibility range.
-
the end border edge of the element’s principal box coincides with the end edge of its view progress visibility range.
-
-
- entry
- Represents the range during which the principal box is entering the view progress visibility range.
- exit
- Represents the range during which the principal box is exiting the view progress visibility range.
- entry-crossing
-
Represents the range during which the principal box crosses the end border edge
-
0% progress represents the position at which the start border edge of the element’s principal box coincides with the end edge of its view progress visibility range.
-
100% progress represents the position at which the end border edge of the element’s principal box coincides with the end edge of its view progress visibility range.
-
- exit-crossing
-
Represents the range during which the principal box crosses the start border edge
-
0% progress represents the position at which the start border edge of the element’s principal box coincides with the start edge of its view progress visibility range.
-
100% progress represents the position at which the end border edge of the element’s principal box coincides with the start edge of its view progress visibility range.
-
In all cases, the writing mode used to resolve the start and end sides is the writing mode of the relevant scroll container. Transforms are ignored, but relative and absolute positioning are accounted for. For sticky-positioned boxes, the box’s startmost offset position is used when identifying 0% progress, and the box’s endmost offset position is used when identifying 100% progress. [CSS-POSITION-3] [CSS-TRANSFORMS-1]
3.2. Calculating Progress for a View Progress Timeline
Progress (the current time) in a view progress timeline is calculated as: distance ÷ range where:
-
distance is the current scroll offset minus the scroll offset corresponding to the start of the cover range
-
range is the scroll offset corresponding to the start of the cover range minus the scroll offset corresponding to the end of the cover range
If the 0% position and 100% position coincide (i.e. the denominator in the current time formula is zero), the timeline is inactive.
3.3. Anonymous View Progress Timelines
3.3.1. The view() notation
The view() functional notation can be used as a <single-animation-timeline> value in animation-timeline and specifies a view progress timeline in reference to the nearest ancestor scroll container. Its syntax is
<view()> = view( [ <axis> || <'view-timeline-inset'> ]? )
By default, view() references the block axis; as for scroll(), this can be changed by providing an explicit <axis> value.
The optional <'view-timeline-inset'> value provides an adjustment of the view progress visibility range, as defined for view-timeline-inset.
Each use of view() corresponds to its own instance of ViewTimeline
in the Web Animations API,
even if multiple elements use view() to reference
the same element with the same arguments.
3.3.2. The ViewTimeline
Interface
dictionary {
ViewTimelineOptions Element ;
subject ScrollAxis = "block"; }; [
axis Exposed =Window ]interface :
ViewTimeline ScrollTimeline {constructor (optional ViewTimelineOptions = {});
options readonly attribute Element subject ;readonly attribute CSSNumericValue startOffset ;readonly attribute CSSNumericValue endOffset ; };
A ViewTimeline
is an AnimationTimeline
that specifies a view progress timeline.
It can be passed to
the Animation
constructor or the animate()
method
to link the animation to a view progress timeline.
subject
, of type Element, readonly-
The element whose principal box’s visibility in the scrollport defines the progress of the timeline.
startOffset
, of type CSSNumericValue, readonly-
Represents the starting (0% progress) scroll position of the view progress timeline as a length offset (in px) from the scroll origin. Null when the timeline is inactive.
endOffset
, of type CSSNumericValue, readonly-
Represents the ending (100% progress) scroll position of the view progress timeline as a length offset (in px) from the scroll origin. Null when the timeline is inactive.
Note: The values of startOffset
and endOffset
are relative to the scroll origin, not the physical top left corner.
Depending on the writing mode of the scroll container,
they therefore might not match scrollLeft
or scrollTop
values,
for example in the horizontal axis in a right-to-left (rtl) writing mode.
Inherited attributes:
source
(inherited fromScrollTimeline
)-
The nearest ancestor of the
subject
whose principal box establishes a scroll container, whose scroll position drives the progress of the timeline. axis
(inherited fromScrollTimeline
)-
Specifies the axis of scrolling that drives the progress of the timeline. See <axis>, above.
currentTime
(inherited fromAnimationTimeline
)-
Represents the current progress of the view progress timeline as a percentage
CSSUnitValue
representing its scroll container’s scroll progress at that position. Null when the timeline is inactive.
ViewTimeline(options)
-
Creates a new
ViewTimeline
object using the following procedure:-
Let timeline be the new
ViewTimeline
object. -
Set the
subject
andaxis
properties of timeline to the corresponding values from options. -
Set the
source
of timeline to thesubject
’s nearest ancestor scroll container element.
-
If the source
or subject
of a ViewTimeline
is an element whose principal box does not exist,
or if its nearest ancestor scroll container has no scrollable overflow,
then the ViewTimeline
is inactive.
Figure out how to incorporate fit/inset abilities.
The values of subject
, source
, and currentTime
are all computed when any of them is requested or updated.
3.4. Named View Progress Timelines
View progress timelines can also be defined declaratively and then referenced by name. See § 4.2 Named Timeline Scoping.
Named view progress timelines are declared in the coordinated value list constructed from the view-timeline-* properties, which form a coordinating list property group with view-timeline-name as the coordinating list base property. See CSS Values 4 § A Coordinating List-Valued Properties.
3.4.1. Naming a View Progress Timeline: the view-timeline-name property
Name: | view-timeline-name |
---|---|
Value: | none | <custom-ident># |
Initial: | none |
Applies to: | all elements |
Inherited: | no |
Percentages: | n/a |
Computed value: | the keyword none or a list of <custom-ident>s |
Canonical order: | per grammar |
Animation type: | not animatable |
Specifies names for any view progress timelines associated with this element’s principal box.
3.4.2. Axis of a View Progress Timeline: the view-timeline-axis property
Name: | view-timeline-axis |
---|---|
Value: | [ block | inline | vertical | horizontal ]# |
Initial: | block |
Applies to: | all elements |
Inherited: | no |
Percentages: | n/a |
Computed value: | a list of the keywords specified |
Canonical order: | per grammar |
Animation type: | not animatable |
Specifies an axis for each named view progress timeline associated with this scroll container.
3.4.3. Inset of a View Progress Timeline: the view-timeline-inset property
Name: | view-timeline-inset |
---|---|
Value: | [ [ auto | <length-percentage> ]{1,2} ]# |
Initial: | auto |
Applies to: | all elements |
Inherited: | no |
Percentages: | relative to the corresponding dimension of the relevant scrollport |
Computed value: | a list consisting of two-value pairs representing the start and end insets each as either the keyword auto or a computed <length-percentage> value |
Canonical order: | per grammar |
Animation type: | by computed value type |
Specifies an inset (positive) or outset (negative) adjustment of the scrollport when determining whether the box is in view when setting the bounds of the corresponding view progress timeline. The first value represents the start inset in the relevant axis; the second value represents the end inset. If the second value is omitted, it is set to the first. The resulting range of the scrollport is the view progress visibility range.
- auto
- Indicates to use the value of scroll-padding.
- <length-percentage>
- Like scroll-padding, defines an inward offset from the corresponding edge of the scrollport.
3.4.4. View Timeline Shorthand: the view-timeline shorthand
Name: | view-timeline |
---|---|
Value: | [ <'view-timeline-name'> <'view-timeline-axis'>? ]# |
Initial: | see individual properties |
Applies to: | all elements |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
This property is a shorthand for setting view-timeline-name and view-timeline-axis in a single declaration. It does not set view-timeline-inset.
Should it reset view-timeline-inset also?
4. Attaching Animations to Scroll-driven Timelines
Animations can be attached to scroll-driven timelines using the scroll-timeline property (in CSS)
or the AnimationTimeline
parameters (in the Web Animations API).
The timeline range to which their active interval is attached
can also be further restricted to a particular timeline range
(see Attaching Animations to Timeline Ranges).
Time-based delays (animation-delay) do not apply to scroll-driven animations, which are distance-based.
4.1. Finite Timeline Calculations
Unlike time-driven timelines, scroll-driven timelines are finite, thus scroll-driven animations are always attached to a finite timeline range. The animation’s
iterations (animation-iteration-count) are set within the limits of this finite range. If the specified duration is auto, then the remaining range is divided by its iteration count (animation-iteration-count) to find the used duration.Note: If the animation has an infinite iteration count,
each iteration duration—
Animations that include absolutely-positioned keyframes (those pinned to a specific point on the timeline, e.g. using named timeline range keyframe selectors in @keyframes) are assumed to have an iteration count of 1 for the purpose of finding those keyframes’ positions relative to 0% and 100%; the entire animation is then scaled to fit the iteration duration and repeated for each iteration.
4.2. Named Timeline Scoping
A named scroll progress timeline or view progress timeline is referenceable in animation-timeline by:
-
the declaring element itself
-
that element’s descendants
If multiple elements have declared the same timeline name, the matching timeline is the one declared on the nearest element in tree order. In case of a name conflict on the same element, scroll progress timelines take precedence over view progress timelines.
We plan to add functionality to expand the scope. [Issue #7759]
4.3. Animation Events
Scroll-driven animations dispatch all the same animation events as the more typical time-driven animations as described in Web Animations § 4.4.18 Animation events, CSS Animations 1 § 4 Animation Events, and CSS Animations 2 § 4.1 Event dispatch.
Note: When scrolling backwards,
the animationstart
event will fire
at the end of the active interval,
and the animationend
event will fire
at the start of the active interval.
However, since the finish
event
is about entering the finished play state,
it only fires when scrolling forwards.
5. Frame Calculation Details
5.1. HTML Processing Model: Event loop
The ability for scrolling to drive the progress of an animation, gives rise to the possibility of layout cycles, where a change to a scroll offset causes an animation’s effect to update, which in turn causes a new change to the scroll offset.
To avoid such layout cycles, animations with a scroll progress timeline update their current time once during step 7.10 of the HTML Processing Model event loop, as step 1 of update animations and send events.
During step 7.14.1 of the HTML Processing Model, any created scroll progress timelines or view progress timelines are collected into an initially stale set. After step 7.14.1 if there are any initially stale timelines, they update their current time, the set of initially stale timelines is cleared and we run and we run an additional step to recalculate styles and update layout. As we only gather stale timelines during the first style and layout calculation, this can only directly cause one additional style recalculation.
Note: Without this additional round of style and layout, initially stale timelines would remain stale (i.e. they would not have a current time) for the remainder of the frame where the timeline was created. This means that animations linked to such a timeline would not produce any effect value for that frame, which could lead to an undesirable initial "flash" in the rendered output.
Note: This section has no effect on forced style and layout
calculations triggered by getComputedStyle()
or similar.
In other words, initially stale timelines are visible as such
through those APIs.
If the step 7.14 of the HTML Processing Model would result in a change of time for any scroll progress timelines or view progress timelines, they will not be re-sampled to reflect the new offset until the next update of the rendering.
Nothing in this section is intended to require
that scrolling block on layout or script.
If a user agent normally composites frames where scrolling has occurred
but the consequences of scrolling have not been fully propagated in layout or script
(for example, scroll
event listeners have not yet run),
the user agent may likewise choose not to sample scroll-driven animations
for that composited frame.
In such cases, the rendered scroll offset
and the state of a scroll-driven animation
may be inconsistent in the composited frame.
6. Privacy Considerations
There are no known privacy impacts of the features in this specification.
7. Security Considerations
There are no known security impacts of the features in this specification.
Appendix A: Named Timeline Ranges
This section should move to CSS-ANIMATIONS-2 and WEB-ANIMATIONS-2.
This specification introduces the concept of named timeline ranges to CSS Animations and Web Animations.
A named timeline range is a named segment of an animation timeline. The start of the segment is represented as 0% progress through the range; the end of the segment is represented as 100% progress through the range. Multiple named timeline ranges can be attached to a given timeline, and multiple such ranges can overlap. For example, the contain range of a view progress timeline overlaps with its cover range. Named timeline ranges are represented by the <timeline-range-name> value type, which indicates a CSS identifier representing one of the predefined named timeline ranges.
Note: In this specification, named timeline ranges must be defined to exist by a specification such as [SCROLL-ANIMATIONS-1]. A future level may introduce APIs for authors to declare their own custom named timeline ranges.
Named Timeline Range Keyframe Selectors
Named timeline range names and percentages can be used to attach keyframes to specific progress points within the named timeline range. The CSS @keyframes rule is extended thus:
<keyframe-selector> = from | to | <percentage [0,100]> | <timeline-range-name> <percentage>
where <timeline-range-name> is the CSS identifier that represents a chosen predefined named timeline range, and the <percentage> after it represents the percentage progress between the start and end of that named timeline range.
Keyframes are attached to the specified point in the timeline. If the timeline does not have a corresponding named timeline range, then any keyframes attached to points on that named timeline range are ignored. It is possible that these attachment points are outside the active interval of the animation; in these cases the automatic from (0%) and to (100%) keyframes are only generated for properties that don’t have keyframes at or earlier than 0% or at or after 100% (respectively).
Attaching Animations to Timeline Ranges
A set of animation keyframes can be attached in reference to named timeline ranges by restricting the animation’s active interval to a specified timeline range with the animation-range properties. Delays (see animation-delay) are set within this restricted range, constricting it further. If a duration (animation-duration) is given, it extends from the end of the start delay until the start of the end delay, and further restricts the range-restricted end.
range start┐ ╺┉┉active interval┉┉╸ ┌range end ┄┄┄┄┄┄┄┄┄┄┄├─────────────╊━━━━━━━━━━━━━━━━━━━╉───────────┤┄┄┄┄┄┄┄┄ ╶┄start delay┄╴ ╶┄end delay┄╴ ╶┄┄┄┄┄ duration┄┄┄┄┄╴
The animation-range properties are reset-only sub-properties of the animation shorthand.
Define application to time-driven animations.
Specifying an Animation’s Timeline Range: the animation-range shorthand
Name: | animation-range |
---|---|
Value: | [ <'animation-range-start'> <'animation-range-end'>? ]# |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
The animation-range property is a shorthand that sets animation-range-start and animation-range-end together in a single declaration.
If <'animation-range-end'> is omitted and <'animation-range-start'> includes a <timeline-range-name> component, then animation-range-end is set to that same <timeline-range-name> and 100%. Otherwise, any omitted longhand is set to its initial value.
animation-range: entry 10% exit 90%; animation-range-start: entry 10%; animation-range-end: exit 90%; animation-range: entry; animation-range-start: entry 0%; animation-range-end: exit 100%; animation-range: 10%; animation-range-start: 10%; animation-range-end: normal; animation-range: entry 10% exit; animation-range-start: entry 10%; animation-range-end: exit 100%; animation-range: 10% exit 90%; animation-range-start: 10%; animation-range-end: exit 90%; animation-range: entry 10% 90%; animation-range-start: entry 10%; animation-range-end: 90%;
What’s the best way to handle defaulting of omitted values here? [Issue #8438]
Specifying an Animation’s Timeline Range Start: the animation-range-start property
Name: | animation-range-start |
---|---|
Value: | [ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]# |
Initial: | normal |
Applies to: | all elements |
Inherited: | no |
Percentages: | relative to the specified named timeline range if one was specified, else to the entire timeline |
Computed value: | list, each item either the keyword normal or a timeline range and progress percentage |
Canonical order: | per grammar |
Animation type: | not animatable |
Shifts the start time of the animation (i.e. where keyframes mapped to 0% progress are attached when the iteration count is 1) to the specified position on the timeline.
- normal
- The start of the animation’s active interval is determined as normal.
- <length-percentage>
- The active interval starts at the specified point on the timeline measuring from the start of the timeline, plus any applicable start delay.
- <timeline-range-name> <length-percentage>?
- The active interval starts at the specified point on the timeline measuring from the start of the specified named timeline range, plus any applicable start delay. If the <length-percentage> is omitted, it defaults to 0%.
Specifying an Animation’s Timeline Range End: the animation-range-end property
Name: | animation-range-end |
---|---|
Value: | [ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]# |
Initial: | normal |
Applies to: | all elements |
Inherited: | no |
Percentages: | relative to the specified named timeline range if one was specified, else to the entire timeline |
Computed value: | list, each item either the keyword normal or a timeline range and progress percentage |
Canonical order: | per grammar |
Animation type: | not animatable |
Shifts the end time of the animation (i.e. where keyframes mapped to 100% progress are attached when the iteration count is 1) to the specified position on the timeline.
- normal
- The end of the animation’s active interval is determined as normal.
- <length-percentage>
- The active interval ends at the specified point on the timeline measuring from the start of the timeline, minus any applicable end delay.
- <timeline-range-name> <length-percentage>?
- The active interval ends at the specified point on the timeline measuring from the start of the specified named timeline range, minus any applicable end delay. If the <length-percentage> is omitted, it defaults to 100%.
Reporting Timeline Range Progress: the getCurrentTime() method
Progress through named ranges is exposed on the AnimationTimeline
object
by the getCurrentTime()
method:
[Exposed =Window ]partial interface AnimationTimeline {CSSNumericValue ?getCurrentTime (optional CSSOMString ); };
rangeName
getCurrentTime(optional rangeName)
method steps are:
-
If this is an inactive timeline, return null.
-
If rangeName is provided:
-
If rangeName is a valid named timeline range on this, let progress be the current progress through that range, expressed as a percentage value.
Create a new unit value from (progress, "percent") and return it.
If the start and end points of the named timeline range coincide, return negative infinity for time values before it, positive infinity for time values after it, and zero for time values coinciding with that point.
-
Otherwise, return null.
-
-
Let current time be the value of this’s
currentTime
internal slot.If this is a
ScrollTimeline
, create a new unit value from (current time, "percent") and return it.Otherwise, create a new unit value from (current time, "ms") and return it.