Scroll-driven vs. scroll-triggered animation
CSS scroll timelines and view timelines are now supported in current versions of Chrome and Edge, and sit behind a feature flag in Firefox. Those provide scroll-driven animations. Scroll-triggered animation is a separate behavior that the Chrome team is still working on: passing a point of no return fires off a complete animation that does not run backward. Wow.js is the familiar JavaScript illustration — content assembles itself in a sequence of entrances as you scroll. CSS has no official solution for this yet, though Ryan Mulligan has demonstrated a workaround by combining animation-timeline with custom properties and style queries.
The gap between the two models matters. Scroll timelines and view timelines are built for animations that reverse when you scroll back up; an element that rolls in and stays put, as on the Wow.js page, is outside their remit. Bramus makes the same observation in his exploration of the topic: The animations run in reverse when scrolling back up. This is not always feasible.
Web-Slinger.css: a no-JavaScript stand-in
A small amount of SCSS and no JavaScript is enough to build a pure CSS parody of Wow.js, named Web-Slinger.css. It leans on the scroll-driven standards already shipping in some major browsers. The library defines two families of classes, .scroll-trigger-n and .on-scroll-trigger-n, plus matching --scroll-trigger-n custom properties inherited from the document root so any class can read them. The naming is more verbose than Wow.js, but splitting triggers from the elements they animate means a marker anywhere on the page can drive a one-off animation on anything else.
A minimal case fires the Animate.css animation flipInY once the user reaches the <div> marked .scroll-trigger-8:
<div class="scroll-trigger-8"></div>
<img
class="on-scroll-trigger-8 animate__animated animate__flipInY"
src="https://i.imgur.com/wTWuv0U.jpeg"
>
Because one trigger can activate any number of animations in the document, the demo also carries a sticky “Cownter” at the top of the page. It increments as new cows appear and swaps in a reset button when the final scroll trigger at the bottom is reached. The markup:
<div class="header">
<h2 class="cownter"></h2>
<div class="animate__animated animate__backInDown on-scroll-trigger-12">
<br>
<a href="#" class="reset">🔁 Play again</a>
</div>
</div>
And the CSS:
.header {
.cownter::after {
--cownter: calc(var(--scroll-trigger-2) + var(--scroll-trigger-4) + var(--scroll-trigger-8) + var(--scroll-trigger-11));
--pluralised-cow: 'cows';
counter-set: cownter var(--cownter);
content: "Have " counter(cownter) " " var(--pluralised-cow) ", man";
}
@container style(--scroll-trigger-2: 1) and style(--scroll-trigger-4: 0) {
.cownter::after {
--pluralised-cow: 'cow';
}
}
a {
text-decoration: none;
color:blue;
}
}
:root:has(.reset:active) * {
animation-name: none;
}
The demo CodePen loads Web-Slinger.css from a separate CodePen, referenced the same way as any external resource. The Cownter also happens to solve the old cow-pluralization problem in pure CSS, a good argument for style queries on their own.
The sticky-element mechanism
The core trick starts from view(): if you can style an element when it enters the viewport, you can style it so it can never leave. It works. One-way animation alone isn't useful output, though — divs that pin themselves to the ceiling the moment they appear are rarely what you want visible.
Named view progress timelines make the technique presentable. The empty scroll trigger element has one job: stick to the top of the viewport as soon as it enters. Setting timeline-scope on the <body> to match that element's view-timeline-name brings it into scope, and Ryan's custom-property toggle plus style queries then let each sticky element trigger arbitrary one-off animations anywhere on the page.
.scroll-trigger {
animation-timeline: view();
animation-name: stick-to-the-top;
animation-fill-mode: both;
animation-duration: 1ms;
}
@keyframes stick-to-the-top {
.1%, to {
position: fixed;
top: 0;
}
}
View CSS code
/** Each trigger element will cause a toggle named with
* the convention `--scroll-trigger-n` to be flipped
* from 0 to 1, which will unpause the animation on
* any element with the class .on-scroll-trigger-n
**/
:root {
animation-name: run-scroll-trigger-1, run-scroll-trigger-2 /*etc*/;
animation-duration: 1ms;
animation-fill-mode: forwards;
animation-timeline: --trigger-timeline-1, --trigger-timeline-2 /*etc*/;
timeline-scope: --trigger-timeline-1, --trigger-timeline-2 /*etc*/;
}
@property --scroll-trigger-1 {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@keyframes run-scroll-trigger-1 {
to {
--scroll-trigger-1: 1;
}
}
/** Add this class to arbitrary elements we want
* to only animate once `.scroll-trigger-1` has come
* into view, default them to paused state otherwise
**/
.on-scroll-trigger-1 {
animation-play-state: paused;
}
/** The style query hack will run the animations on
* the element once the toggle is set to true
**/
@container style(--scroll-trigger-1: 1) {
.on-scroll-trigger-1 {
animation-play-state: running;
}
}
/** The trigger element which sticks to the top of
* the viewport and activates the one-way animation
* that will unpause the animation on the
* corresponding element marked with `.on-scroll-trigger-n`
**/
.scroll-trigger-1 {
view-timeline-name: --trigger-timeline-1;
}
Costs and the standardization question
The generic library compiles from 95 lines of SCSS. The trade-off is size: the more triggers you need, the larger the compiled CSS grows. The numbered classes are also non-semantic. Native support that tied a scroll-triggered element to its trigger by ID would be preferable — something in the spirit of the popovertarget attribute on HTML buttons, except placed on each target element and naming the trigger's ID, the reverse of how popovertarget works.
<!-- This is speculative — do not use -->
<scroll-trigger id="my-scroll-trigger"></scroll-trigger>
<div class="rollIn" scrolltrigger="my-scroll-trigger">Hello world</div>
Bramus has teased that scroll-triggered animations are something we'd like to ship in a future version of Chrome, but it still needs a bit of work before we can do that.
A standardized browser implementation could do worse than a convention resembling Web-Slinger.css for declaring these animations. The library is a prototype: reference it in experimental CodePens, or fork it if you have better ideas about how scroll-triggered animations ought to be standardized.



