|
| 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 |
0 commit comments