Unofficial and experimental plugin that provides utilities for scroll-driven animations in Tailwind CSS v4+. An earlier release of the plugin supports Tailwind CSS v3.4+.
Install the plugin from npm.
Then register the plugin in your main CSS file.
Install the v0.3 release of the plugin, which supports Tailwind CSS v3.4+.
Then add the plugin to your tailwind.config.js.
CSS animations consist of two components, a set of keyframes and a style describing the animation. Let's declare a simple translate-down keyframe set and apply it to an element we want to control by a scroll timeline.
@keyframes translate-down {
to {
translate: 0;
}
}<div class="animate-translate-down timeline">
<!-- The animation should be controlled by the timeline. -->
</div>To effectively control the animation, make sure to declare the timeline in the code after the animation. By default, the shorthand animation property sets the animation-timeline: auto unless set otherwise. However, using this plugin and Tailwind CSS animations ensures that the declaration order is correct.
.timeline { /* This timeline would be overriden */
animation-timeline: scroll(y);
}
.animate-translate-down {
animation: translate-down 3s cubic-bezier(0.65, 0.05, 0.17, 0.99) forwards;
}
.timeline { /* This is the correct order */
animation-timeline: scroll(y);
}Scroll the container.
timeline before animate-translate-downanimate-translate-down before timeline