@@ -392,7 +392,7 @@ following effects:
392392
393393 The second <<scroll-offset>> , if provided, determines the trigger's {{ScrollTrigger/endScrollOffset}} .
394394
395- ## @trigger rules ## {#trigger-rules}
395+ ## '' @trigger'' rules ## {#trigger-rules}
396396
397397The <dfn>@trigger</dfn> at-rule allows conditioning the application of CSS rules
398398on the scroll progress of a [=scroll container=] . It is defined as follows:
@@ -419,8 +419,8 @@ Issue: Do we need 'animation-trigger' at all, or is ''@trigger'' sufficient?
419419## Examples ## {#trigger-examples}
420420
421421<div class="example">
422+ Spin an element while the page's vertical scroll offset is within a range
422423 <pre class="lang-javascript">
423- // Spin an element while the page's vertical scroll offset is within a range
424424 let spinner = document.getElementById("spinner");
425425 let effect = new KeyframeEffect(
426426 spinner,
@@ -448,8 +448,8 @@ Issue: Do we need 'animation-trigger' at all, or is ''@trigger'' sufficient?
448448</div>
449449
450450<div class="example">
451+ The same thing with CSS, using 'animation-trigger'
451452 <pre class="lang-css">
452- /* The same thing with CSS, using animation-trigger */
453453 @keyframes spin {
454454 from {
455455 transform: rotate(0);
@@ -473,8 +473,8 @@ Issue: Do we need 'animation-trigger' at all, or is ''@trigger'' sufficient?
473473</div>
474474
475475<div class="example">
476+ The same thing with CSS, using ''@trigger''
476477 <pre class="lang-css">
477- /* The same thing with CSS, using @trigger */
478478 @keyframes spin {
479479 from {
480480 transform: rotate(0);
@@ -673,7 +673,101 @@ following effects:
673673
674674## Examples ## {#timeline-examples}
675675
676- TBD
676+ <div class="example">
677+ Draw a reading progress bar along the top of the page as the user scrolls
678+ <pre class="lang-css">
679+ #progress {
680+ position: fixed;
681+ top: 0;
682+ width: 0;
683+ height: 2px;
684+ background-color: red;
685+ }
686+ </pre>
687+ <pre class="lang-javascript">
688+ let progress = document.getElementById("progress");
689+ let effect = new KeyframeEffect(
690+ progress,
691+ [
692+ { width: "0vw" },
693+ { width: "100vw" }
694+ ],
695+ {
696+ duration: 1000,
697+ easing: "linear"
698+ });
699+ let timeline = new ScrollTimeline({
700+ trigger: new ScrollTrigger({
701+ scrollSource: document.documentElement,
702+ orientation: "vertical",
703+ kind: "range"
704+ })
705+ });
706+ let animation = new Animation(effect, timeline);
707+ animation.play();
708+ </pre>
709+ </div>
710+
711+ <div class="example">
712+ The same thing with CSS, using 'animation-trigger'
713+ <pre class="lang-css">
714+ @keyframes progress {
715+ from {
716+ width: 0vw;
717+ }
718+ to {
719+ width: 100vw;
720+ }
721+ }
722+ html {
723+ scroll-container-name: root;
724+ }
725+ #progress {
726+ position: fixed;
727+ top: 0;
728+ width: 0;
729+ height: 2px;
730+ background-color: red;
731+ animation-name: progress;
732+ animation-duration: 1s;
733+ animation-timing-function: linear;
734+ animation-trigger: scroll(root, vertical);
735+ animation-timeline: scroll();
736+ }
737+ </pre>
738+ </div>
739+
740+ <div class="example">
741+ The same thing with CSS, using ''@trigger''
742+ <pre class="lang-css">
743+ @keyframes progress {
744+ from {
745+ width: 0vw;
746+ }
747+ to {
748+ width: 100vw;
749+ }
750+ }
751+ html {
752+ scroll-container-name: root;
753+ }
754+ #progress {
755+ position: fixed;
756+ top: 0;
757+ width: 0;
758+ height: 2px;
759+ background-color: red;
760+ }
761+ @trigger scroll(root, vertical) {
762+ #progress {
763+ animation-name: progress;
764+ animation-duration: 1s;
765+ animation-timing-function: linear;
766+ animation-timeline: scroll();
767+ }
768+ }
769+ </pre>
770+ </div>
677771
678772# Avoiding cycles with layout # {#avoiding-cycles}
679773
0 commit comments