Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for CSS Scroll-driven animations #27075

Merged
merged 51 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a7bc7ca
Add docs for CSS Scroll-driven animations
chrisdavidmills May 31, 2023
5991259
Merge branch 'main' into scroll-driven-animations
chrisdavidmills May 31, 2023
e712222
Deleting unwanted article
chrisdavidmills May 31, 2023
2f65b27
prettier fixes
chrisdavidmills May 31, 2023
a26a947
Fix flaws
chrisdavidmills May 31, 2023
84de2fd
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 5, 2023
4e5749c
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills Jun 5, 2023
20e38c8
Correct casing of scroll-driven animations article title and links
chrisdavidmills Jun 5, 2023
bbdfccb
Update landing page to remove unnecessary demos and replace with link
chrisdavidmills Jun 7, 2023
ba8c49d
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 7, 2023
01e69c9
Update files/en-us/web/css/@keyframes/index.md
chrisdavidmills Jun 13, 2023
197176c
Update files/en-us/web/css/@keyframes/index.md
chrisdavidmills Jun 13, 2023
53f9716
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills Jun 13, 2023
e99bfc3
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills Jun 13, 2023
2151d22
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills Jun 13, 2023
cbbca54
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 13, 2023
ac08fc1
Few tweaks based on dipikabh comments
chrisdavidmills Jun 13, 2023
aa44825
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 13, 2023
c17f74b
Update guide link position
chrisdavidmills Jun 14, 2023
c6d8fce
Update files/en-us/web/css/view-timeline/index.md
chrisdavidmills Jun 14, 2023
33be0ba
Update files/en-us/web/css/view-timeline/index.md
chrisdavidmills Jun 14, 2023
88b3b44
Update files/en-us/web/css/view-timeline-name/index.md
chrisdavidmills Jun 14, 2023
5f394ed
Update files/en-us/web/css/view-timeline-inset/index.md
chrisdavidmills Jun 14, 2023
c0fb447
Update files/en-us/web/css/animation-range-end/index.md
chrisdavidmills Jun 14, 2023
83c76bc
Update files/en-us/web/css/animation-range/index.md
chrisdavidmills Jun 14, 2023
b7cad11
Update files/en-us/web/css/animation-range/index.md
chrisdavidmills Jun 14, 2023
bf018e6
Update files/en-us/web/css/animation-range/index.md
chrisdavidmills Jun 14, 2023
23ffbd5
Update files/en-us/web/css/animation-timeline/scroll/index.md
chrisdavidmills Jun 14, 2023
b011cc4
Update files/en-us/web/css/animation-timeline/view/index.md
chrisdavidmills Jun 14, 2023
52c7f87
Update files/en-us/web/css/animation-timeline/view/index.md
chrisdavidmills Jun 14, 2023
c816587
Update files/en-us/web/css/animation-timeline/view/index.md
chrisdavidmills Jun 14, 2023
2500b3d
Update files/en-us/web/css/animation-timeline/scroll/index.md
chrisdavidmills Jun 14, 2023
bfae138
Update files/en-us/web/css/view-timeline/index.md
chrisdavidmills Jun 14, 2023
c098257
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills Jun 14, 2023
b36d7da
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills Jun 14, 2023
eb75b32
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills Jun 14, 2023
1d45627
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills Jun 14, 2023
cd89784
Update files/en-us/web/css/animation-timeline/scroll/index.md
chrisdavidmills Jun 14, 2023
25e087d
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 14, 2023
237788f
Make animation-range* see also sections consistent
chrisdavidmills Jun 14, 2023
c4ad158
prettier fix
chrisdavidmills Jun 14, 2023
40ba7b8
Add timeline-scope, remove getCurrentTime(), update dashed-ident details
chrisdavidmills Jun 19, 2023
4db70a5
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 19, 2023
8bd007d
Add experimental status to timeline-scope
chrisdavidmills Jun 20, 2023
af22102
Loads of updates
chrisdavidmills Jun 20, 2023
2729f70
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 20, 2023
d57f834
Attempt to fix prettier error
chrisdavidmills Jun 20, 2023
645ee8f
Remove deprecated axis values and fix a few errors
chrisdavidmills Jun 21, 2023
61d6567
Show clear examples of rangeEnd and rangeStart string values
chrisdavidmills Jun 21, 2023
a9720ab
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 21, 2023
d9f3b54
Merge branch 'main' into scroll-driven-animations
chrisdavidmills Jun 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions files/en-us/web/api/animationtimeline/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ browser-compat: api.AnimationTimeline

{{ APIRef("Web Animations") }}

The `AnimationTimeline` interface of the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API) represents the timeline of an animation. This interface exists to define timeline features (inherited by {{domxref("DocumentTimeline")}} and future timeline types) and is not itself directly used by developers. Anywhere you see `AnimationTimeline`, you should use `DocumentTimeline` or any other timeline type instead.
The `AnimationTimeline` interface of the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API) represents the timeline of an animation. This interface exists to define timeline features, inherited by other timeline types:

- {{domxref("DocumentTimeline")}}
- {{domxref("ScrollTimeline")}}
- {{domxref("ViewTimeline")}}

## Instance properties

- {{domxref("AnimationTimeline.currentTime")}} {{ReadOnlyInline}}
- {{domxref("AnimationTimeline.currentTime", "currentTime")}} {{ReadOnlyInline}}
- : Returns the time value in milliseconds for this timeline or `null` if this timeline is inactive.

## Specifications
Expand All @@ -24,6 +28,7 @@ The `AnimationTimeline` interface of the [Web Animations API](/en-US/docs/Web/AP

## See also

- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- {{domxref("DocumentTimeline")}}
- {{domxref("DocumentTimeline")}}, {{domxref("ScrollTimeline")}}, {{domxref("ViewTimeline")}}
- {{domxref("Document.timeline")}}
- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
60 changes: 55 additions & 5 deletions files/en-us/web/api/element/animate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,31 @@ animate(keyframes, options)
milliseconds), **or** an Object containing one or more timing properties described in the [`KeyframeEffect()` options parameter](/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#parameters) and/or the following options:

- `id` {{optional_inline}}
- : A property unique to `animate()`: a string
with which to reference the animation.
- : A property unique to `animate()`: A string with which to reference the animation.
- `rangeEnd` {{optional_inline}}

- : Specifies the end of an animation's attachment range along its timeline, i.e. where along the timeline an animation will end. The JavaScript equivalent of the CSS {{cssxref("animation-range-end")}} property. `rangeEnd` can take several different value types, as follows:

- A string that can be `normal` (meaning no change to the animation's attachment range), a CSS {{cssxref("length-percentage")}} representing an offset, a `<timeline-range-name>`, or a `<timeline-range-name>` with a `<length-percentage>` following it. See [`animation-range`](/en-US/docs/Web/CSS/animation-range) for a detailed description of the available values. Also check out the [View Timeline Ranges Visualizer](https://scroll-driven-animations.style/tools/view-timeline/ranges/), which shows exactly what the different values mean in an easy visual format.
- An object containing `rangeName` (a string) and `offset` (a {{domxref("CSSNumericValue")}}) properties representing a `<timeline-range-name>` and `<length-percentage>`, as described in the previous bullet. For example:

```js
{
rangeName: 'entry',
offset: CSS.percent('100'),
}
```

- A {{domxref("CSSNumericValue")}} representing an offset, for example:

```js
CSS.percent("100");
```

- `rangeStart` {{optional_inline}}
- : Specifies the start of an animation's attachment range along its timeline, i.e. where along the timeline an animation will start. The JavaScript equivalent of the CSS {{cssxref("animation-range-start")}} property. `rangeStart` can take the same value types as `rangeEnd`.
- `timeline` {{optional_inline}}
- : A property unique to `animate()`: the {{domxref("AnimationTimeline")}} to associate with the animation. Defaults to {{domxref("Document.timeline")}}.
- : A property unique to `animate()`: The {{domxref("AnimationTimeline")}} to associate with the animation. Defaults to {{domxref("Document.timeline")}}. The JavaScript equivalent of the CSS {{cssxref("animation-timeline")}} property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rangeStart and rangeEnd are missing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I originally left them out because they didn't seem to do anything. I think it was around the time when the implementation was in progress. They do seem to work now, although some of the value effects aren't what I'd quite expect. Do all of the value types as specced work, in your experience?

My descriptions are in my next commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my experience they seemed to work well. Only used the string variation though, where I – for example – set rangeEnd to "cover 100%" instead of an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, I wonder whether I should just list the string values then, at least for now, while we investigate the other options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so to clear this up, I've added clear examples of the string values, and made the values used in the on-page example string values. If it turns out people want more information of examples on the other value types, we can always add them later.

### Return value

Expand Down Expand Up @@ -137,6 +158,33 @@ let rotate360 = [{ transform: "rotate(360deg)" }];
We have only specified the end state of the animation, and the beginning state is
implied.

### timeline, rangeStart, and rangeEnd

Typical usage of the `timeline`, `rangeStart`, and `rangeEnd` properties might look like this:

```js
const img = document.querySelector("img");

const timeline = new ViewTimeline({
subject: img,
axis: "block",
});

img.animate(
{
opacity: [0, 1],
transform: ["scaleX(0)", "scaleX(1)"],
},
{
fill: "both",
duration: 1,
timeline,
rangeStart: { rangeName: "entry", offset: CSS.percent("0") },
rangeEnd: CSS.percent("50"),
}
);
```

## Specifications

{{Specifications}}
Expand All @@ -147,6 +195,8 @@ implied.

## See also

- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- {{domxref("Element.getAnimations()")}}
- {{domxref("Animation")}}
- {{domxref("Element.getAnimations()")}}
- {{cssxref("animation-range-end")}}, {{cssxref("animation-range-start")}}, {{cssxref("animation-timeline")}}
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
46 changes: 46 additions & 0 deletions files/en-us/web/api/scrolltimeline/axis/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "ScrollTimeline: axis property"
short-title: axis
slug: Web/API/ScrollTimeline/axis
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.ScrollTimeline.axis
---

{{APIRef("Web Animations")}}{{SeeCompatTable}}

The **`axis`** read-only property of the
{{domxref("ScrollTimeline")}} interface returns an enumerated value representing the scroll axis that is driving the progress of the timeline.

## Value

An enumerated value. Possible values are:

- `"block"`
- : The scrollbar on the block axis of the scroll container, which is the axis in the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `"y"`, while for vertical writing modes, it is the same as `"x"`.
- `"inline"`
- : The scrollbar on the inline axis of the scroll container, which is the axis in the direction parallel to the flow of text in a line. For horizontal writing modes, this is the same as `"x"`, while for vertical writing modes, this is the same as `"y"`.
- `"y"`
- : The scrollbar on the vertical axis of the scroll container.
- `"x"`
- : The scrollbar on the horizontal axis of the scroll container.

## Examples

See the main {{domxref("ScrollTimeline")}} page for an example.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("ScrollTimeline")}}
- {{domxref("AnimationTimeline")}}, {{domxref("ViewTimeline")}}
- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
123 changes: 123 additions & 0 deletions files/en-us/web/api/scrolltimeline/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: ScrollTimeline
slug: Web/API/ScrollTimeline
page-type: web-api-interface
status:
- experimental
browser-compat: api.ScrollTimeline
---

{{APIRef("Web Animations")}}{{SeeCompatTable}}

The **`ScrollTimeline`** interface of the {{domxref("Web Animations API", "Web Animations API", "", "nocode")}} represents a scroll progress timeline (see [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) for more details).

Pass a `ScrollTimeline` instance to the {{domxref("Animation.Animation", "Animation()")}} constructor or the {{domxref("Element.animate()", "animate()")}} method to specify it as the timeline that will control the progress of the animation.

{{InheritanceDiagram}}

## Constructor

- {{domxref("ScrollTimeline.ScrollTimeline", "ScrollTimeline()")}}
- : Creates a new `ScrollTimeline` object instance.

## Instance properties

_This interface also inherits the properties of its parent, {{domxref("AnimationTimeline")}}._

- {{domxref("ScrollTimeline.source", "source")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Returns a reference to the scrollable element (_scroller_) whose scroll position is driving the progress of the timeline and therefore the animation.
- {{domxref("ScrollTimeline.axis", "axis")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Returns an enumerated value representing the scroll axis that is driving the progress of the timeline.

## Instance methods

_This interface inherits the methods of its parent, {{domxref("AnimationTimeline")}}._

## Examples

### Displaying the source and axis of a scroll progress timeline

In this example, we animate an element with a `class` of `box` along a view progress timeline — it animates across the screen as the document scrolls. We output the `source` element and scroll `axis` to an `output` element in the top-right corner.

#### HTML

The HTML for the example is shown below.

```html
<div class="content"></div>
<div class="box"></div>
<div class="output"></div>
```

#### CSS

The CSS for the example looks like this:

```css
.content {
height: 2000px;
}

.box {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: rebeccapurple;
position: fixed;
top: 20px;
left: 0%;
}

.output {
font-family: Arial, Helvetica, sans-serif;
position: fixed;
top: 5px;
right: 5px;
}
```

#### JavaScript

In the JavaScript, we grab references to the `box` and `output` `<div>`s, then create a new `ScrollTimeline`, specifying that the element that will drive the scroll timeline progress is the document ({{htmlelement("html")}}) element, and the scroll axis is the `block` axis. We then animate the `box` element with the Web Animations API. Last of all, we display the source element and axis in the `output` element.

```js
const box = document.querySelector(".box");
const output = document.querySelector(".output");

const timeline = new ScrollTimeline({
source: document.documentElement,
axis: "block",
});

box.animate(
{
rotate: ["0deg", "720deg"],
left: ["0%", "100%"],
},
{
timeline,
}
);

output.textContent = `Timeline source element: ${timeline.source.nodeName}. Timeline scroll axis: ${timeline.axis}`;
```

#### Result

Scroll to see the box being animated.

{{EmbedLiveSample("Displaying the source and axis of a scroll progress timeline", "100%", "320px")}}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
- {{domxref("AnimationTimeline")}}, {{domxref("ViewTimeline")}}
61 changes: 61 additions & 0 deletions files/en-us/web/api/scrolltimeline/scrolltimeline/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "ScrollTimeline: ScrollTimeline() constructor"
short-title: ScrollTimeline()
slug: Web/API/ScrollTimeline/ScrollTimeline
page-type: web-api-constructor
status:
- experimental
browser-compat: api.ScrollTimeline.ScrollTimeline
---

{{APIRef("History API")}}

The **`ScrollTimeline()`** constructor creates a new {{domxref("ScrollTimeline")}} object instance.

## Syntax

```js-nolint
new ScrollTimeline(options)
```

### Parameters

- `options`

- : An object that can contain the following properties:

- `source`
- : A reference to an {{domxref("Element")}} representing the scrollable element (_scroller_) whose scroll position will drive the progress of the timeline.
- `axis` {{optional_inline}}

- : An enumerated value representing the scroll axis that will drive the progress of the timeline. Possible values are:

- `"block"`: The scrollbar on the block axis of the scroll container, which is the axis in the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `"y"`, while for vertical writing modes, it is the same as `"x"`.
- `"inline"`: The scrollbar on the inline axis of the scroll container, which is the axis in the direction parallel to the flow of text in a line. For horizontal writing modes, this is the same as `"x"`, while for vertical writing modes, this is the same as `"y"`.
- `"y"`: The scrollbar on the vertical axis of the scroll container.
- `"x"`: The scrollbar on the horizontal axis of the scroll container.

If omitted, `axis` defaults to `"block"`.

### Return value

A new {{domxref("ScrollTimeline")}} object instance.

## Examples

See the main {{domxref("ScrollTimeline")}} page for an example.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
- {{domxref("ScrollTimeline")}}
- {{domxref("AnimationTimeline")}}, {{domxref("ViewTimeline")}}
37 changes: 37 additions & 0 deletions files/en-us/web/api/scrolltimeline/source/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: "ScrollTimeline: source property"
short-title: source
slug: Web/API/ScrollTimeline/source
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.ScrollTimeline.source
---

{{APIRef("Web Animations")}}{{SeeCompatTable}}

The **`source`** read-only property of the
{{domxref("ScrollTimeline")}} interface returns a reference to the scrollable element (_scroller_) whose scroll position is driving the progress of the timeline and therefore the animation.

## Value

An {{domxref("Element")}}.

## Examples

See the main {{domxref("ScrollTimeline")}} page for an example.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
- {{domxref("ScrollTimeline")}}
- {{domxref("AnimationTimeline")}}, {{domxref("ViewTimeline")}}
Loading