ScrollFlow
A tiny JavaScript library for the scroll effects most sites actually need: elements that reveal as you scroll, a touch of parallax, and a reading progress bar. No dependencies, no build step.
3,928 bytes gzipped, JS and CSS together. That is the whole library.
Playground
Pick an animation, set a delay, press replay. This box is animated by ScrollFlow itself, running on this page.
<div data-sf-reveal="fade-up" data-sf-delay="200">
What it does
Reveal on scroll
Seven animations — fade, slide, zoom — that play as an element enters the viewport: on the compositor via CSS scroll-driven animations where the browser supports them, on IntersectionObserver everywhere else. Add one attribute and you are done.
7 animations
Parallax that stays put
Movement is calculated from the element's own position against the centre of the viewport, so an element halfway down the page behaves the same as one at the top.
1 attribute
Reading progress bar
A flat bar at the top of the page, driven by transform so it never triggers layout. The one on this page is ScrollFlow's.
on by default
Respects reduced motion
Visitors who ask their system for reduced motion get the content straight away: no reveal travel, no parallax, no smooth scrolling.
automatic
Plays well with real sites
Content added later? Call refresh(). Done with it? destroy() removes the listeners, the observer, and the bar. No JavaScript at all? Everything stays visible.
2 methods
Install in a minute
Three ways in. All of them end with the same two files.
CDN
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/aqles/scrollflow@3.0.0/dist/scrollflow.css">
<script src="https://cdn.jsdelivr.net/gh/aqles/scrollflow@3.0.0/dist/scrollflow.min.js" data-auto-init></script>
npm
npm install @aqles/scrollflow
import ScrollFlow from '@aqles/scrollflow';
import '@aqles/scrollflow/dist/scrollflow.css';
new ScrollFlow();
Files, no tooling
Download scrollflow.js and scrollflow.css from the dist folder, drop them in your project, and link them like the CDN snippet above. Then mark up your elements:
<h2 data-sf-reveal="fade-up">Hello</h2>
<p data-sf-reveal="fade-up" data-sf-delay="150">150 ms later, any number works.</p>
<div data-sf-parallax="0.2">I drift, gently.</div>
Parallax, honestly measured
The offset is the distance between the element's centre and the viewport's centre, times the speed you set. At the centre the offset is zero, and the distance is capped at half the viewport, so nothing ever jumps or drifts away. Give a parallax element a parent with room to spare — it moves within the space around it.
Speed 0.05, barely moving.
Speed 0.12, moving more.
The disc drifts at 0.18.
API
Options
| Option | Default | What it does |
|---|---|---|
revealThreshold | 0.1 | How much of an element must be visible before it reveals. |
rootMargin | "0px 0px -50px 0px" | IntersectionObserver root margin for reveals. |
parallaxSpeed | 0.5 | Fallback speed for parallax elements without a valid value. |
progressBar | true | Show the reading progress bar. |
smoothScroll | true | Smooth anchor scrolling via CSS scroll-behavior. Links are never intercepted. |
once | true | Reveal once and stop watching. Set false to hide elements again when they leave. |
duration | null | Reveal duration in ms. Overrides the --sf-duration CSS variable. |
easing | null | Reveal easing. Overrides the --sf-easing CSS variable. |
Methods
| Method | What it does |
|---|---|
refresh() | Re-scan the page and pick up elements added since the library started. |
destroy() | Disconnect the observer, remove the listeners and the progress bar, and undo the styles this instance set. |
Full examples — reveal, parallax, progress and smooth scrolling — live in the examples folder. Found a bug? Open an issue.