The plugin provides utilities for a subset of CSS scroll-driven animation properties:
animation-timelinescroll-timeline, view-timelineanimation-rangetimeline-scopeThe single most impressive feature of scroll-driven animations is an anonymous animation timeline. It allows to easily trigger anything just by scrolling the page. Use the timeline utility which defaults to animation-timeline: scroll(y) and also provides an option to set custom timeline name with a modifier.
This demo showcases how to create a simple progress bar just by adding one utility class to the element. We define the anonymous scroll timeline by adding timeline to the progress bar.
animate-scale-to-right timeline<div>
<div class="animate-scale-to-right timeline">
<!-- The progress bar is controlled by the anonymous scroll(y) timeline. -->
</div>
<div>
...
</div>
</div>@keyframes scale-to-right {
to {
width: 100%;
}
}This demo showcases how to make the element appear after entering the view frame. We define the anonymous view timeline by adding timeline-view to this element.
animate-appear timeline-view<div>
...
<div class="animate-appear timeline-view">
<!-- This element is controlled by its own anonymous view() timeline. -->
</div>
...
</div>@keyframes appear {
0% {
opacity: 0;
transform: scale(0.5);
}
40% {
opacity: 1;
transform: scale(1.1);
}
60%,
100% {
opacity: 1;
transform: scale(1);
}
}Utility class setting the named scroll progress timeline, which is set on a scrollable element.
Utility class setting the named view progress timeline, which is set on a subject inside another scrollable element.
Animation range start controls where along the timeline an animation will start. It is set on the animated element.
Scroll the container to see each how range utility class affects the animation.
range-on-entryrangerange-containrange-on-exitview-timeline/demo<div class="scope/demo">
<!-- The --demo timeline has scope outside its defining element -->
<div class="animate-scale-to-right range-on-entry timeline/demo">
<!-- This element is controlled by the --demo timeline -->
</div>
...
<div className="view-timeline/demo">
<!-- Controlling element -->
</div>
</div>@keyframes scale-to-right {
to {
width: 100%;
}
}Timeline scope allows to control animations outside the element which defines the timeline.
This demo showcases the usage of the plugin to reveal the navigation bar. The view-timeline/navbar utility sets up the animation timeline, which is then scoped out of the defining element by scope/navbar. The navigation bar is controlled by this timeline with the timeline/navbar utility. Utility class range-on-exit is set to limit the timeline duration.
<div class="scope/navbar">
<!-- The --navbar timeline has scope outside its defining element -->
<div class="animate-translate-down timeline/navbar range-on-exit">
<!-- Navbar is shown when the controlling element leaves the frame -->
</div>
<div>
...
<div className="view-timeline/navbar">
<!-- Controlling element -->
</div>
...
</div>
</div>@keyframes translate-down {
to {
translate: 0;
}
}Use the no-animations modifier to apply fallback styling in browsers which do not support scroll-driven animations yet.
animate...timeline-translate-y-20no-animations:translate-y-0<div>
<div class="animate-translate-down timeline -translate-y-20 no-animations:translate-y-0">
<!-- This element falls back to translate-y-0 -->
</div>
...
</div>