DocumentTimeline: DocumentTimeline() constructor
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{ APIRef("Web Animations") }}
The **DocumentTimeline()** constructor of the Web Animations API creates a new instance of the {{domxref("DocumentTimeline")}} object associated with the active document of the current browsing context.
Syntax
new DocumentTimeline(options)Parameters
options{{optional_inline}}- : An object specifying options for the new timeline. The following properties are available:
originTime{{optional_inline}}- : A
numberthat specifies the zero time for the {{domxref("DocumentTimeline")}}
as a number of milliseconds relative to {{domxref("Performance.timeOrigin")}}. Defaults to 0.
Examples
Origin time
A {{domxref("DocumentTimeline")}} with an originTime of zero counts time starting from {{domxref("Performance.timeOrigin")}}. This is the same behavior as {{domxref("Document.timeline")}}.
const timeline = new DocumentTimeline();
console.log(timeline.currentTime === document.timeline.currentTime); // trueSetting a non-zero originTime will offset the {{domxref("DocumentTimeline")}} from {{domxref("Document.timeline")}} by that amount:
const offsetTimeline = new DocumentTimeline({ originTime: 500 });
console.log(document.timeline.currentTime - offsetTimeline.currentTime); // 500A {{domxref("DocumentTimeline")}} relative to the current moment can be constructed with:
const nowTimeline = new DocumentTimeline({
originTime: document.timeline.currentTime,
});
console.log(nowTimeline.currentTime); // 0Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- Web Animations API
- {{domxref("AnimationTimeline")}}
- {{domxref("DocumentTimeline")}}