-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
chrisdavidmills
merged 51 commits into
mdn:main
from
chrisdavidmills:scroll-driven-animations
Jun 26, 2023
Merged
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 5991259
Merge branch 'main' into scroll-driven-animations
chrisdavidmills e712222
Deleting unwanted article
chrisdavidmills 2f65b27
prettier fixes
chrisdavidmills a26a947
Fix flaws
chrisdavidmills 84de2fd
Merge branch 'main' into scroll-driven-animations
chrisdavidmills 4e5749c
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills 20e38c8
Correct casing of scroll-driven animations article title and links
chrisdavidmills bbdfccb
Update landing page to remove unnecessary demos and replace with link
chrisdavidmills ba8c49d
Merge branch 'main' into scroll-driven-animations
chrisdavidmills 01e69c9
Update files/en-us/web/css/@keyframes/index.md
chrisdavidmills 197176c
Update files/en-us/web/css/@keyframes/index.md
chrisdavidmills 53f9716
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills e99bfc3
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills 2151d22
Update files/en-us/web/css/css_scroll-driven_animations/index.md
chrisdavidmills cbbca54
Merge branch 'main' into scroll-driven-animations
chrisdavidmills ac08fc1
Few tweaks based on dipikabh comments
chrisdavidmills aa44825
Merge branch 'main' into scroll-driven-animations
chrisdavidmills c17f74b
Update guide link position
chrisdavidmills c6d8fce
Update files/en-us/web/css/view-timeline/index.md
chrisdavidmills 33be0ba
Update files/en-us/web/css/view-timeline/index.md
chrisdavidmills 88b3b44
Update files/en-us/web/css/view-timeline-name/index.md
chrisdavidmills 5f394ed
Update files/en-us/web/css/view-timeline-inset/index.md
chrisdavidmills c0fb447
Update files/en-us/web/css/animation-range-end/index.md
chrisdavidmills 83c76bc
Update files/en-us/web/css/animation-range/index.md
chrisdavidmills b7cad11
Update files/en-us/web/css/animation-range/index.md
chrisdavidmills bf018e6
Update files/en-us/web/css/animation-range/index.md
chrisdavidmills 23ffbd5
Update files/en-us/web/css/animation-timeline/scroll/index.md
chrisdavidmills b011cc4
Update files/en-us/web/css/animation-timeline/view/index.md
chrisdavidmills 52c7f87
Update files/en-us/web/css/animation-timeline/view/index.md
chrisdavidmills c816587
Update files/en-us/web/css/animation-timeline/view/index.md
chrisdavidmills 2500b3d
Update files/en-us/web/css/animation-timeline/scroll/index.md
chrisdavidmills bfae138
Update files/en-us/web/css/view-timeline/index.md
chrisdavidmills c098257
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills b36d7da
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills eb75b32
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills 1d45627
Update files/en-us/web/css/animation-timeline/index.md
chrisdavidmills cd89784
Update files/en-us/web/css/animation-timeline/scroll/index.md
chrisdavidmills 25e087d
Merge branch 'main' into scroll-driven-animations
chrisdavidmills 237788f
Make animation-range* see also sections consistent
chrisdavidmills c4ad158
prettier fix
chrisdavidmills 40ba7b8
Add timeline-scope, remove getCurrentTime(), update dashed-ident details
chrisdavidmills 4db70a5
Merge branch 'main' into scroll-driven-animations
chrisdavidmills 8bd007d
Add experimental status to timeline-scope
chrisdavidmills af22102
Loads of updates
chrisdavidmills 2729f70
Merge branch 'main' into scroll-driven-animations
chrisdavidmills d57f834
Attempt to fix prettier error
chrisdavidmills 645ee8f
Remove deprecated axis values and fix a few errors
chrisdavidmills 61d6567
Show clear examples of rangeEnd and rangeStart string values
chrisdavidmills a9720ab
Merge branch 'main' into scroll-driven-animations
chrisdavidmills d9f3b54
Merge branch 'main' into scroll-driven-animations
chrisdavidmills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
files/en-us/web/api/scrolltimeline/scrolltimeline/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rangeStart
andrangeEnd
are missing here.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.