Skip to content

Commit b7536cd

Browse files
Elchi3hamishwillee
andauthored
Document AnimationTimeline.duration (#40979)
* Document AnimationTimeline.duration * Update files/en-us/web/api/animationtimeline/duration/index.md Co-authored-by: Hamish Willee <[email protected]> --------- Co-authored-by: Hamish Willee <[email protected]>
1 parent a6d1fd3 commit b7536cd

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: "AnimationTimeline: duration property"
3+
short-title: duration
4+
slug: Web/API/AnimationTimeline/duration
5+
page-type: web-api-instance-property
6+
browser-compat: api.AnimationTimeline.duration
7+
---
8+
9+
{{ APIRef("Web Animations") }}
10+
11+
The **`duration`** read-only property of the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)'s {{domxref("AnimationTimeline")}} interface returns the maximum value for this timeline or `null`.
12+
13+
Note that the derived interfaces {{domxref("ViewTimeline")}} and {{domxref("ScrollTimeline")}} always return a duration of 100%, while {{domxref("DocumentTimeline")}} has no duration, and returns `null`.
14+
15+
## Value
16+
17+
A number representing the timeline's duration (the maximum value for this timeline) or `null`.
18+
19+
## Examples
20+
21+
### View timeline duration
22+
23+
The {{domxref("ViewTimeline")}} always returns a duration of 100% as a {{domxref("CSSUnitValue")}}.
24+
25+
```js
26+
const subject = document.querySelector(".subject");
27+
const timeline = new ViewTimeline({
28+
subject,
29+
axis: "block",
30+
});
31+
32+
timeline.duration; // CSSUnitValue { value: 100, unit: "percent" }
33+
```
34+
35+
### Scroll timeline duration
36+
37+
The {{domxref("ScrollTimeline")}} always returns a duration of 100% as a {{domxref("CSSUnitValue")}}.
38+
39+
```js
40+
const timeline = new ScrollTimeline({
41+
source: document.documentElement,
42+
axis: "block",
43+
});
44+
45+
timeline.duration; // CSSUnitValue { value: 100, unit: "percent" }
46+
```
47+
48+
### Document timeline duration
49+
50+
The {{domxref("DocumentTimeline")}} has no duration.
51+
52+
```js
53+
document.timeline.duration; // null
54+
```
55+
56+
## Specifications
57+
58+
{{Specifications}}
59+
60+
## Browser compatibility
61+
62+
{{Compat}}
63+
64+
## See also
65+
66+
- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
67+
- {{domxref("AnimationTimeline")}}
68+
- {{domxref("DocumentTimeline")}} inherits this property
69+
- {{domxref("ScrollTimeline")}} inherits this property
70+
- {{domxref("ViewTimeline")}} inherits this property

files/en-us/web/api/animationtimeline/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The `AnimationTimeline` interface of the [Web Animations API](/en-US/docs/Web/AP
1717

1818
- {{domxref("AnimationTimeline.currentTime", "currentTime")}} {{ReadOnlyInline}}
1919
- : Returns the time value in milliseconds for this timeline or `null` if this timeline is inactive.
20+
- {{domxref("AnimationTimeline.duration", "duration")}} {{ReadOnlyInline}}
21+
- : Returns the maximum value for this timeline or `null`.
2022

2123
## Specifications
2224

0 commit comments

Comments
 (0)