@@ -562,6 +562,51 @@ target is adjacent to the scrollport but not yet visible. The upcoming threshold
562562value will allow authors to control the amount of target that needs to be
563563visible.
564564
565+ <div class="example">
566+ Here is a basic example showing how element-based offsets can be used to declare
567+ an scroll-linked animation that occurs when an element enters the scroller
568+ scrollport and ends once it exits the scrollport.
569+
570+ <figure>
571+ <img src="img/example-element-based.svg" width="600"
572+ alt="Example usage of element-based offset.">
573+ <figcaption>
574+ Usage of element-based offsets to create enter/exit triggers.<br>
575+ The left figure shows the scroller and target being aligned at 'end' edge.<br>
576+ The right figure shows them being aligned at 'start' edge.
577+ </figcaption>
578+ </figure>
579+
580+
581+ Note that here we are expecting a typical top to bottom scrolling and thus
582+ consider the entrance to coincide when target's start edge is flushed with
583+ with scrollport's <strong> end edge</strong> and viceversa for exit.
584+
585+ <pre class='lang-javascript'>
586+ if (window.matchMedia('(prefers-reduced-motion: no-preference)' ).matches) {
587+ const scrollableElement = document.querySelector('#container' );
588+ const image = document.querySelector('#image' );
589+
590+ const timeline = new ScrollTimeline({
591+ source: scrollableElement,
592+ start: {target: image, edge: 'end' },
593+ end: {target: image, edge: 'start' },
594+ });
595+
596+ const slideIn = target.animate({
597+ transform: ['translateX(0)',q 'translateX(50vw)'] ,
598+ opacity: [0, 1]
599+ }, {
600+ timeline:timeline,
601+ duration: 1000
602+ }
603+ );
604+ }
605+ </pre>
606+
607+
608+ </div>
609+
565610### The effective time range of a {{ScrollTimeline}} ### {#effective-time-range-algorithm}
566611
567612The <dfn>effective time range</dfn> of a {{ScrollTimeline}} is calculated as
0 commit comments