-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for CSS Scroll-driven animations (#27075)
* Add docs for CSS Scroll-driven animations * Deleting unwanted article * prettier fixes * Fix flaws * Update files/en-us/web/css/css_scroll-driven_animations/index.md Co-authored-by: Estelle Weyl <[email protected]> * Correct casing of scroll-driven animations article title and links * Update landing page to remove unnecessary demos and replace with link * Update files/en-us/web/css/@keyframes/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/@keyframes/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/css_scroll-driven_animations/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/css_scroll-driven_animations/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/css_scroll-driven_animations/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Few tweaks based on dipikabh comments * Update guide link position * Update files/en-us/web/css/view-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/view-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/view-timeline-name/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/view-timeline-inset/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-range-end/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-range/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-range/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-range/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/scroll/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/view/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/view/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/view/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/scroll/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/view-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Update files/en-us/web/css/animation-timeline/scroll/index.md Co-authored-by: Dipika Bhattacharya <[email protected]> * Make animation-range* see also sections consistent * prettier fix * Add timeline-scope, remove getCurrentTime(), update dashed-ident details * Add experimental status to timeline-scope * Loads of updates * Attempt to fix prettier error * Remove deprecated axis values and fix a few errors * Show clear examples of rangeEnd and rangeStart string values --------- Co-authored-by: Estelle Weyl <[email protected]> Co-authored-by: Dipika Bhattacharya <[email protected]>
- Loading branch information
1 parent
757f33e
commit 34bc6ac
Showing
38 changed files
with
2,938 additions
and
249 deletions.
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.