Pass a ViewTimeline instance to the Animation() constructor or the animate() method to specify it as the timeline that will control the progress of the animation.
Returns a reference to the subject element whose visibility within its nearest ancestor scrollable element (scroller) is driving the progress of the timeline and therefore the animation.
Returns a CSSNumericValue representing the starting (0% progress) scroll position of the timeline as an offset from the start of the overflowing section of content in the scroller.
Returns a CSSNumericValue representing the ending (100% progress) scroll position of the timeline as an offset from the start of the overflowing section of content in the scroller.
Instance methods
This interface inherits the methods of its parent, ScrollTimeline.
Examples
Displaying the subject and offsets of a view progress timeline
In this example, we animate an element with a class of subject along a view progress timeline — it animates when moved upwards through the document as it scrolls. We also output the subject, startOffset, and endOffset values to an output element in the top-right corner.
HTML
The HTML for the example is shown below.
html
<divclass="content"><h1>Content</h1><p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam
quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat
interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat
vivamus at augue.
</p><p>
Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate
dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna
duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus.
Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum
arcu vitae elementum curabitur vitae nunc sed velit.
</p><divclass="subject animation"></div><p>
Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu
cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet
dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non
tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam
vel quam elementum. Nibh praesent tristique magna sit amet purus gravida
quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat
imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi
scelerisque. Netus et malesuada fames ac.
</p><divclass="output"></div></div>
In the JavaScript, we grab references to the subject and output<div>s, then create a new ViewTimeline, associating it with the subject element to specify that the timeline progress is based on this element's visibility through its scrolling ancestor, setting a block axis, and setting inset values to adjust the position of the box in which the subject is deemed to be visible.
We then animate the subject element with the Web Animations API. Last of all, we display the subject, startOffset, and endOffset values in the output element.