GODRICH
#css-animation#button#loader#transition#scroll#dashboard#ui#design-trends

scroll-driven animations Fallback: 9 Scenes

Scroll-driven animations should run only where supported, with the finished end state elsewhere. Where should a screen rest without scroll-linked animation?

What scroll-driven animations Do in CSS

Zip contents and how to open

There are two timelines: animation-timeline: scroll() reads a scroll container's progress, and view() reads how far one element has crossed the window.

Demos Are a Canvas Computation Model

The nine demos are canvas calculation models, because the render tool freezes CSS animation, so no animation-timeline rule could run inside them.

Numbers called measured come from real timelines and a real observer in Chrome driven by Playwright; unsupported cells are an emulation that forces the support check to fail.

9 Fallback Scenes, Detection to Matrix

The render tool took 24 captures of a 480×300 canvas over 2 seconds and compared 23 neighboring pairs; the Chrome build was not recorded, so it is unverified.

Cumulative area is the share of pixels that ever differ from the first frame, and intensity is their mean color difference (0 to 255). Moved frames counts captures that differ from the previous one.

Scene Cumulative area Moved frames Mean intensity
01 scroll timeline 35.8% 20/23 46.0
02 element visibility range 27.5% 19/23 46.9
03 support detection 37.5% 19/23 37.0
04 static end state 36.3% 19/23 71.1
05 transition fallback 35.8% 19/23 47.4
06 frame cost 35.1% 23/23 47.7
07 reduced-motion overlap 22.8% 10/23 78.1
08 scroll value math 35.5% 19/23 46.8
09 browser scenario 33.1% 20/23 46.5

01Scroll Timeline: Page Progress Bar

progAt divides the scroll position by MAX_SCROLL, while the script panel reads the lagged scrollLag, LAG_FRAMES 1 frame late.

Per pass it rewrites the bar SCRIPT_CALLS 108 times, and the two bars drift apart by up to 1.6%p.

It fits reading progress; skip it where the timeline exists, since two bars would answer one scroll.

Scroll Timeline: A Bar Filled by Page Progress

01 · Scroll Timeline: A Bar Filled by Page Progress — Measured area 35.842% · moving frames 20/23Original by GODRICH · SCSS and React ship in the zip · See the password

SCRIPT_CALLSMAX_GAPLAG_FRAMES
    function scrollAt(t) {
        if (t < UP_TO + 0.2) {
            return MAX_SCROLL * EASE_IN_OUT(clamp((t - UP_FROM) / (UP_TO - UP_FROM), 0, 1));
        }
        return MAX_SCROLL * (1 - EASE_IN_OUT(clamp((t - DOWN_FROM) / (DOWN_TO - DOWN_FROM), 0, 1)));
    }
    // scroll progress 0 to 1 — the value the timeline uses. scroll position ÷ (document height − window height)
    function progAt(s) { return clamp(s / MAX_SCROLL, 0, 1); }
    // the value the script reads from a scroll event and writes to the bar is a position from LAG_FRAMES frames ago (LAG_FRAMES = 1)
    const LAG_FRAMES = 1;
    function scrollLag(t) { return scrollAt(Math.max(0, t - LAG_FRAMES / FPS)); }

02View Range: Play While Crossing

viewProg is 0 when the card's top meets the window bottom and 1 when its bottom clears the top, and rangeVal refolds it into RANGE_START to RANGE_END.

A span of 0 to 50% ends the change at 68px; a real animation-range: cover 0% 50% also ended at 68px and first changed at 1px (measured).

It fits card and image reveals.

Element Visibility Range: Play Only While It Crosses

02 · Element Visibility Range: Play Only While It Crosses — Measured area 27.504% · moving frames 19/23Original by GODRICH · SCSS and React ship in the zip · See the password

RANGE_STARTRANGE_ENDviewProg
    // 0 when the card's top edge touches the window's bottom edge, 1 when the card's bottom edge clears the window's top
    function viewProg(s) { return clamp((s + VIEW_H - CARD_Y) / (VIEW_H + CARD_H), 0, 1); }
    function rangeVal(v, rs, re) { return clamp((v * 100 - rs) / (re - rs), 0, 1); }
    // the scroll positions (px) where the span starts and ends
    function scrollAtPct(pct) { return CARD_Y - VIEW_H + (pct / 100) * (VIEW_H + CARD_H); }
    function curRange(v) { return rangeVal(v, RANGE_START, RANGE_END); }

03Support Detection: CSS or Script

When detection passes only the CSS panel fills the bar, otherwise only the script panel does, flipping at SWITCH_T 1.2 seconds via unsupportedAt.

It fits an audience that mixes supported and unsupported browsers.

Support Detection: Conditional Rule and Script Fallback

03 · Support Detection: Conditional Rule and Script Fallback — Measured area 37.535% · moving frames 19/23Original by GODRICH · SCSS and React ship in the zip · See the password

SWITCH_TFINAL_CSSFINAL_JS
    const SWITCH_T = 1.2;
    function unsupportedAt(t) { return simOn || t >= SWITCH_T; }
    // the two panels' final widths (px) and the largest gap while moving (px)
    const FINAL_CSS = VW * progAt(scrollAt(UP_TO));
    const FINAL_JS = VW * progAt(scrollLag(UP_TO + 0.2));
    const GAP_PX = (MAX_GAP_PCT() / 100) * VW;

04Static End State: Finished Look

opOf returns 1 for the good panel and 0 for the bad one once unsupported, so after UNSUP_T 0.7 seconds 3 cards show against 0. With support, both panels show 3 cards at the end of the scroll.

It fits adding a new feature step by step; skip a transparent start state as the base value, since unsupported visitors then see 0 of 3 cards.

Static End State: Leave the Finished Look When Unsupported

04 · Static End State: Leave the Finished Look When Unsupported — Measured area 36.261% · moving frames 19/23Original by GODRICH · SCSS and React ship in the zip · See the password

UNSUP_TVIS_UN_GOODVIS_UN_BAD
    function unsupportedAt(t) { return simOn || t >= UNSUP_T; }
    function vOf(i, s) { return clamp((s + VIEW_H - CARDS_Y[i]) / (VIEW_H + CH4), 0, 1); }
    // card i's opacity — with support, the span value; without, the base value (good panel 1, bad panel 0)
    function opOf(i, s, un, good) {
        if (un) {
            return good ? 1 : 0;
        }
        return clamp(vOf(i, s) * 100 / RANGE4_END, 0, 1);
    }

05Transition Fallback: Play Once

visFrac measures the visible fraction, and at trigAt, where it reaches THRESHOLD 0.2, a one-shot transition starts at scroll 12px, matching a real IntersectionObserver (measured).

It fits keeping an entrance effect without support; skip it for a bar that must rewind on scroll up, since one shot cannot play backward.

Transition Fallback: Play Once on Entering the Screen

05 · Transition Fallback: Play Once on Entering the Screen — Measured area 35.815% · moving frames 19/23Original by GODRICH · SCSS and React ship in the zip · See the password

THRESHOLDTRANS_StTrig
    // the fraction of the card visible in the window — height risen above the window's bottom edge ÷ card height
    function visFrac(s) { return clamp((VIEW_H - (CARD_Y - s)) / CARD5_H, 0, 1); }
    function viewV(s) { return clamp((s + VIEW_H - CARD_Y) / (VIEW_H + CARD5_H), 0, 1); }
    function tlVal(s) { return clamp(viewV(s) * 100 / RANGE5_END, 0, 1); }
    // the first time the observer fires — the first moment the visible fraction reaches THRESHOLD
    function trigAt() {
        for (let t = 0; t <= LAP_S; t += 1 / 240) {
            if (visFrac(scrollAt(t)) >= THRESHOLD) {
                return t;
            }
        }
        return LAP_S;
    }

06Frame Cost: Events vs Timeline

handler reads scrollTop, computes progress, writes the bar width and reads a position once more, while bareScroll only sets the position.

Over three real Chrome sessions the mean frame interval was 16.667ms in both modes, a 0% gap.

Handler time here was 0.202 to 0.238ms, under 1.5% of the frame budget, so skip a rewrite done only for speed.

Frame Comparison: Scroll Events Versus a Timeline

06 · Frame Comparison: Scroll Events Versus a Timeline — Measured area 35.146% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password

NODESmsAivB
    // timeline-panel mode — only the position is set. No value is read, and no bar value exists in script
    function bareScroll(s) { rig.scrollTop = s; }
    // script-panel mode — what the scroll event handler does: read the position, compute progress, write the bar width, read an element position once more
    function handler(s) {
        rig.scrollTop = s;
        const p = rig.scrollTop / (rig.scrollHeight - rig.clientHeight);
        rigBar.style.width = (p * VW) + 'px';
        const last = rigDoc.lastElementChild;
        if (last) {
            void last.getBoundingClientRect().top;
        }
    }

07Reduced Motion Overlap: Two Settings

The four functions in FN7 give 21 distinct opacity values when supported with reduction off, 2 without support (EDGE_AT 0.25), and 1 with reduction on.

It fits screens that honor both scroll linking and the motion setting.

Reduced Motion Overlap: Timeline and Setting Both On

07 · Reduced Motion Overlap: Timeline and Setting Both On — Measured area 22.837% · moving frames 10/23Original by GODRICH · SCSS and React ship in the zip · See the password

EDGE_ATDISTFN7
    const EDGE_AT = 0.25;
    function viewV(s) { return clamp((s + VIEW_H - CARD_Y) / (VIEW_H + CARD7_H), 0, 1); }
    const FN7 = [
        function (p) { return clamp(p * 100 / RANGE7_END, 0, 1); },
        function (p) { void p; return 1; },
        function (p) { return p >= EDGE_AT ? 1 : 0; },
        function (p) { void p; return 1; }
    ];

08Scroll Value Math: Read-Only Progress

okProg divides the position by the travelable distance and misses a real timeline bar by at most 0.007%p, while naiveProg divides by document height and misses by up to 33.3%p.

It fits building the same progress value without a timeline; skip the document-height division, whose table is in the trap section.

Scroll Value Calculation: Progress Read Without Writing

08 · Scroll Value Calculation: Progress Read Without Writing — Measured area 35.529% · moving frames 19/23Original by GODRICH · SCSS and React ship in the zip · See the password

MAX_SCROLLMAX_GAP_NAIVEMEAN_GAP_OK
    const GAP_OK = gapStats(okProg, true);
    const GAP_NAIVE = gapStats(naiveProg, true);
    const MAX_GAP_OK = GAP_OK[0];
    const MAX_GAP_NAIVE = GAP_NAIVE[0];
    const MEAN_GAP_OK = GAP_OK[1];
    const MEAN_GAP_NAIVE = GAP_NAIVE[1];
    // span gauge — the gap between the timeline value and the wrong formula at every 25% of scroll progress
    function segGap(pct) { return Math.abs(pct / 100 - naiveProg(MAX_SCROLL * pct / 100)) * 100; }

09Browser Scenario: Three Environments

Across the supported, no-timeline (emulated) and reduction-on cells, the signature fingerprints over 11 points all differ, so distinctCells returns 3/3.

It fits ordering browser checks before release; partial support and script off are emulated, not real browsers.

Browser Scenarios: Full, Partial and No Support

09 · Browser Scenarios: Full, Partial and No Support — Measured area 33.069% · moving frames 20/23Original by GODRICH · SCSS and React ship in the zip · See the password

SCENARIO_COUNTsignaturedistinctCells
    // environment e's [bar value, card opacity] — 0 supported · 1 no timeline · 2 reduction on · 3 partial support · 4 script off
    function envOf(e, s, sl) {
        const v = viewV(s);
        if (e === 0) {
            return simOn ? envOf(1, s, sl) : [progAt(s), clamp(v * 100 / RANGE9_END, 0, 1)];
        }
        if (e === 1) {
            return [progAt(sl), viewV(sl) >= EDGE9 ? 1 : 0];
        }
        if (e === 2) {
            return [1, 1];
        }
        if (e === 3) {
            return [progAt(s), 1];
        }
        return [1, 1];
    }

Which Fallback Should You Pick?

With the timeline present, leave the work to CSS; without it, keep content from vanishing first, then decide how much motion to keep.

Situation What to pick Section
Support detection is true timeline rules inside @supports 03
No support, content must not vanish end state as the base value 04
No support, only an entrance effect needed observer playing once 05
No support, a progress value needed read-only computation 08
Reduced motion is on instant final state 07

For ranges see Scroll and View Timeline Range Patterns, for observer triggers Scroll Trigger Animation Engine, and for basics CSS Scroll Animations.

How Scroll Progress Reaches the Screen

The Fallback Rebuilds the Same Value

A timeline converts scroll position to 0 through 1. Without one, a script repeats that computation; this code measures how far the two bars in 01 drift apart.

    function gapMax() {
        let m = 0;
        for (let t = 0; t <= LAP_S; t += 1 / FPS) {
            m = Math.max(m, Math.abs(progAt(scrollAt(t)) - progAt(scrollLag(t))) * 100);
        }
        return m;
    }
    const MAX_GAP = gapMax();

Adding a Fallback Without a Library

Keep the End State as Base, Add the Timeline Conditionally

On a real screen it is one block: write the end state in the base rule and declare animation and timeline only inside @supports.

.card {
    opacity: 1;
}

@supports (animation-timeline: view()) {
    .card {
        animation: reveal linear both;
        animation-timeline: view();
        animation-range: cover 0% 50%;
    }
}

@keyframes reveal {
    from { opacity: 0; }
    to { opacity: 1; }
}

This is a reader example, not demo source; the zip has example-scroll-timeline.html with the same code. The animation shorthand resets animation-timeline, so declare the timeline after it.

Fill the Gap With Script When Support Is Missing

Listen to scroll only when CSS.supports('animation-timeline: scroll()') is false, and read scrollTop ÷ (scrollHeight − clientHeight).

Where Fallbacks Break: Trap Cases

Dividing by Document Height Leaves the Bar Short

The table compares the formulas from 08 with a real timeline bar at 277 points.

Formula Max drift Mean drift
scroll position ÷ 200 (right) 0.007%p 0.003%p
scroll position ÷ document height 300 (wrong) 33.3%p 15.9%p
right formula + one frame late 1.8%p 0.72%p
wrong formula + one frame late 33.5%p 15.9%p

A Named Timeline Needs a Common Ancestor

To read a timeline named scroll-timeline: --s from outside the scroll container, the common ancestor must declare timeline-scope: --s.

In the measurement, the bar stopped moving when its parent declared that same name separately.

.page {
    timeline-scope: --list;
}

.list {
    overflow-y: auto;
    scroll-timeline: --list y;
}

.indicator {
    animation: fill linear;
    animation-timeline: --list;
}

This is also a reader example; put the declaration on the closest ancestor holding both the scroll container and the bar.

Reading Right After Writing Returns the Old Value

In the measurement, getComputedStyle read right after changing scrollTop returned the old bar width.

What Changed When One Value Moved

Change Value Effect
A later range start 02 RANGE_START 0 → 25 In the demo the change ends at 136px instead of 68px and the card turns opaque from 34px instead of 0px. A real view() kept the end at 68px and moved the first change from 1px to 35px
A higher observer threshold 05 THRESHOLD 0.2 → 0.6 Playback starts at 36px instead of 12px, and the real observer moved the same way
More environments to compare 09 SCENARIO_COUNT 3 → 5 Distinct looks grow only to 4, and reduction-on and script-off become a look-alike pair

The zip bundles the HTML, CSS and JS of the nine scenes, the React version and the reader example files; the password is x975kqwb.

Browser Compatibility and Support Table

For css scroll animation browser support on real screens, it lists the first version of each feature, read from mdn/browser-compat-data.

Feature Chrome Safari Firefox Edge
animation-timeline 115 26 159 follows Chrome
scroll() 115 26 159 follows Chrome
view() 115 26 159 follows Chrome
animation-range 115 26 159 follows Chrome
timeline-scope 116 26 159 follows Chrome

Note: Edge's "follows Chrome" is a mirror entry in browser-compat-data, which repeats the Chrome value with no separate version.

Source: MDN CSS scroll-driven animations

Source: MDN animation-timeline · MDN @supports

Data: animation-timeline.json, animation-range.json and timeline-scope.json

Which Row to Watch

The latest cell is Firefox 159, so treat older builds as having no timeline and use 03's split with 04's base.

Accessibility With Reduced Motion

This CSS is ready to paste and is not demo source. Turning off only the animation keeps the timeline rules, and the end-state base value becomes the final screen.

@media (prefers-reduced-motion: reduce) {
    .card,
    .progress {
        animation: none;
    }
}

Place this block after the @supports block so the same selectors override each other.

For criteria on the setting, read the prefers-reduced-motion Guide.

With Reduction On, One Frame Is Drawn

The nine scenes play without input. With reduction on, they draw one frame at REST_S 2.2 seconds, and two captures matched under Chrome's reduce emulation.

The Emulation Switch and Screen Readers

The U key or button toggles the unsupported emulation, and arrow keys change the setting in 02, 05, 06 and 09.

The status line is aria-live="off", and a role="status" paragraph speaks only when the mode changes.

Space, Enter and P pause and R restarts; the loop stops in hidden tabs, and flashing stays at 3 per second or fewer.

Fallback FAQ: How Do You Detect Support?

Scroll driven animations safari: which version works?

Per the compatibility table, Safari supports animation-timeline from version 26. Below that, split with 03's detection and show 04's end state or 05's one-shot play.

How do you detect support?

In CSS, an @supports (animation-timeline: scroll()) block asks; in script, CSS.supports('animation-timeline: scroll()') asks the same condition. Scene 03 compared both branches.

What happens to the timeline with reduced motion on?

Turn it off with animation: none inside a prefers-reduced-motion: reduce block and the end-state base value remains. Scene 07 confirmed one look regardless of support.

Enter the archive password

The password is inside this article. You will find it as you read.