The DocumentTimeline() constructor of the Web Animations API creates a new instance of the DocumentTimeline object associated with the active document of the current browsing context.
The DocumentTimeline() constructor of the Web Animations API creates a new instance of the DocumentTimeline object associated with the active document of the current browsing context.
js
new DocumentTimeline(options)
options Optional
An object specifying options for the new timeline. The following properties are available:
originTime Optional
A number that specifies the zero time for the DocumentTimeline as a number of milliseconds relative to Performance.timeOrigin. Defaults to 0.
A DocumentTimeline with an originTime of zero counts time starting from Performance.timeOrigin. This is the same behavior as Document.timeline.
js
const timeline = new DocumentTimeline(); console.log(timeline.currentTime === document.timeline.currentTime); // true
Setting a non-zero originTime will offset the DocumentTimeline from Document.timeline by that amount:
js
const offsetTimeline = new DocumentTimeline({ originTime: 500 }); console.log(document.timeline.currentTime - offsetTimeline.currentTime); // 500
A DocumentTimeline relative to the current moment can be constructed with:
js
const nowTimeline = new DocumentTimeline({ originTime: document.timeline.currentTime, }); console.log(nowTimeline.currentTime); // 0
| Specification |
|---|
| Web Animations # dom-documenttimeline-documenttimeline |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
DocumentTimeline |
84 | 84 | 75 | No | 70 | 13.1 | 84 | 84 | 79 | 60 | 13.4 | 14.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DocumentTimeline/DocumentTimeline