timeline-trigger-active-range-start CSS property
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The timeline-trigger-active-range-start CSS property specifies the start point of a scroll-triggered animation trigger's active range.
Syntax
/* Keyword */
timeline-trigger-active-range-start: auto;
timeline-trigger-active-range-start: normal;
/* <length-percentage> */
timeline-trigger-active-range-start: 10%;
timeline-trigger-active-range-start: 50px;
/* Named timeline range */
timeline-trigger-active-range-start: contain;
timeline-trigger-active-range-start: exit;
/* Named timeline range plus offset */
timeline-trigger-active-range-start: entry 5%;
timeline-trigger-active-range-start: contain 100px;
/* Multiple range start values */
timeline-trigger-active-range-start:
contain,
entry 5%;
/* Global values */
timeline-trigger-active-range-start: inherit;
timeline-trigger-active-range-start: initial;
timeline-trigger-active-range-start: revert;
timeline-trigger-active-range-start: revert-layer;
timeline-trigger-active-range-start: unset;
Values
Specified as one or more values, separated by commas. Possible values are:
auto-
The
timeline-trigger-active-range-startproperty is set to the same value as thetimeline-trigger-activation-range-startproperty. This is the default value. normal-
Equivalent to
cover 0%for a view progress timelinetimeline-trigger-source, andscroll 0%for a scroll progress timelinetimeline-trigger-source. <length-percentage>-
Specifies a length or percentage value measured from the beginning of the
normaltimeline. <timeline-range-name>-
Specifies the start (
0%) of the named timeline range. <timeline-range-name><length-percentage>-
Specifies a length or percentage value measured from the beginning of the specified named timeline range.
Percentages are relative to the length of the named timeline range if one is specified, or the timeline represented by normal if not.
Description
When creating CSS scroll-triggered animations, the timeline-trigger-active-range-start property can be set to explicitly define the start of the trigger's active range.
The default value is auto, which sets the timeline-trigger-active-range-start value to the same as the timeline-trigger-activation-range-start.
A value of normal is equivalent to cover 0% for a view progress timeline timeline-trigger-source, and scroll 0% for a scroll progress timeline timeline-trigger-source.
If the <timeline-range-name> value does not include a <length-percentage>, it defaults to 0% of the named timeline range. If a <timeline-range-name> is not included, the timeline range defaults to cover for a view progress timeline source, and scroll for a scroll progress timeline source.
The timeline-trigger-active-range-start property, along with the timeline-trigger-active-range-end property, can also be set using the timeline-trigger-active-range shorthand.
Specifying multiple range start values
When you specify multiple comma-separated values on a single timeline-trigger-active-range-start property, they are applied to the timeline triggers in the order in which the timeline-trigger-names appear. When the number of triggers and timeline-trigger-active-range-start property values do not match, they are applied in the same way as multiple animation property values.
For example, if multiple timeline-trigger-name values are set, but only a single timeline-trigger-active-range-start value is set, the timeline-trigger-active-range-start will apply to all the timeline-trigger-names. If two timeline-trigger-active-range-start values are set, they will cycle between the timeline-trigger-names until all of them have a timeline-trigger-active-range-start value set. And so on.
Consider these declarations:
timeline-trigger-name: --my-trigger, --my-other-trigger, --another-trigger;
timeline-trigger-active-range-start:
contain,
entry 5%;
In this case, --my-trigger will use the contain range start and --my-other-trigger will use the entry 5% range start. As there are three names but only two range starts, the range starts are cycled, so the third trigger name, --another-trigger, will use the contain range start.
Formal definition
| Initial value | auto |
|---|---|
| Applies to | all elements |
| Inherited | no |
| Percentages | Relative to the specified named timeline range if specified, otherwise relative to the entire timeline |
| Computed value | A list where each item may be 'normal', a length percentage, or a timeline range name and a length percentage |
| Animation type | Not animatable |
Formal syntax
timeline-trigger-active-range-start =
[ auto | normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#
<length-percentage> =
<length> |
<percentage>
Examples
>Basic usage
In this example, we inset the start of a scroll-triggered animation trigger's active range by setting a custom timeline-trigger-active-range-start value.
HTML
Our markup contains two <div> elements, one to animate and one on which to create a trigger, plus some basic text content to cause the page to scroll. We have hidden the text content for brevity.
<div class="animated">I am animated</div>
...
<div class="trigger">I create the trigger</div>
...
CSS
The animated <div> element's position is set to fixed, positioning it near the top-left of the scrollport to enable us to see when its animation starts and stops.
.animated {
position: fixed;
top: 25px;
left: 25px;
}
Next, we define the @keyframes for the rotate animation we will use later:
@keyframes rotate {
from {
rotate: 0deg;
}
to {
rotate: 360deg;
}
}
Using the animation shorthand, the .animated element has the rotate animation applied. Without an associated trigger, the element would start animating when the page loads. The animation-trigger property makes it a triggered animation. The value references a timeline-trigger-name of --t and specifies two <animation-action> values — play and pause — which specify that the animation will play on activation, and pause on deactivation.
.animated {
animation: rotate 3s infinite linear;
animation-trigger: --t play pause;
}
The .trigger <div> element creates the animated <div>'s trigger via the following properties:
- A
timeline-trigger-namewith value--t, which is equal to the identifier referenced in the animated<div>'sanimation-triggerproperty value, associating the two together. - A
timeline-trigger-sourcewith valueview(), which sets the timeline trigger as a view progress timeline, and the element providing the timeline trigger as the nearest scrolling ancestor element. - A
timeline-trigger-activation-rangeofcontain 30% contain 60%, which sets the trigger's activation range to a small portion of thecontainrange. - A
timeline-trigger-active-range-startofcover 0%. When not explicitly set, thetimeline-trigger-active-range-endvalue defaults to thetimeline-trigger-activation-range-endvalue —contain 60%— so we end up with an overalltimeline-trigger-active-rangeofcover 0% contain 60%.
.trigger {
timeline-trigger-name: --t;
timeline-trigger-source: view();
timeline-trigger-activation-range: contain 30% contain 60%;
timeline-trigger-active-range-start: cover 0%;
}
Result
Try scrolling the content up. The animation plays when the tracked <div> moves into the narrow activation range between 30% and 60% of the way through the timeline range. It will then pause as soon as the tracked <div> goes above the 60% point.
When you scroll downwards again, the animation will start when the tracked element reaches the 60% point; you can now scroll the tracked element completely off the bottom of the scrollport before the animation will pause again. This is because we extended the start of the active range, but not the end.
Specifications
| Specification |
|---|
| Animation Triggers> # propdef-timeline-trigger-active-range-start> |
Browser compatibility
See also
timeline-trigger-active-range-endtimeline-trigger-active-rangeshorthand propertytimeline-trigger-name,timeline-trigger-source, andtimeline-trigger-activation-rangetimeline-triggershorthand property- Using CSS scroll-triggered animations
- CSS animation triggers module
- CSS animations module