DocumentTimeline: DocumentTimeline() constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
TheDocumentTimeline() constructor of theWeb Animations API creates a new instance of theDocumentTimeline object associated with the active document of the current browsing context.
In this article
Syntax
new DocumentTimeline(options)Parameters
optionsOptionalAn object specifying options for the new timeline. The following properties are available:
originTimeOptionalA
numberthat specifies the zero time for theDocumentTimelineas a number of milliseconds relative toPerformance.timeOrigin.Defaults to0.
Examples
>Origin time
ADocumentTimeline with anoriginTime of zero counts timestarting fromPerformance.timeOrigin. This is the same behaviorasDocument.timeline.
const timeline = new DocumentTimeline();console.log(timeline.currentTime === document.timeline.currentTime); // trueSetting a non-zerooriginTime will offset theDocumentTimelinefromDocument.timeline by that amount:
const offsetTimeline = new DocumentTimeline({ originTime: 500 });console.log(document.timeline.currentTime - offsetTimeline.currentTime); // 500ADocumentTimeline relative to the current moment can be constructed with:
const nowTimeline = new DocumentTimeline({ originTime: document.timeline.currentTime,});console.log(nowTimeline.currentTime); // 0Specifications
| Specification |
|---|
| Web Animations> # dom-documenttimeline-documenttimeline> |