DocumentTimeline: DocumentTimeline() constructor
Baseline 2022
Newly available
Since September 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
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.
Syntax
new DocumentTimeline(options)
Parameters
optionsOptional-
An object specifying options for the new timeline. The following properties are available:
originTimeOptional-
A
numberthat specifies the zero time for theDocumentTimelineas a number of milliseconds relative toPerformance.timeOrigin. Defaults to0.
Examples
Origin time
A DocumentTimeline with an originTime of zero counts time
starting from Performance.timeOrigin. This is the same behavior
as Document.timeline.
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:
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:
const nowTimeline = new DocumentTimeline({
originTime: document.timeline.currentTime,
});
console.log(nowTimeline.currentTime); // 0
Specifications
| Specification |
|---|
| Web Animations # dom-documenttimeline-documenttimeline |
Browser compatibility
| desktop | mobile | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
DocumentTimeline() constructor | |||||||||||