31 / blog / performanceJune 20267 min read

Zero-JS SVG scroll animations

Since v1.1.0, svg-scroll-draw automatically hands eligible animations to the browser's own scroll-driven animation engine using animation-timeline: view(). Zero per-frame JavaScript. No scroll listeners. No requestAnimationFrame loop.

  • Performance
  • animation-timeline
  • view()
  • Scroll timeline
JS per frame
0 bytes
Scroll listeners
none
Chrome · Safari · Firefox
115 · 26 · 159
Opt-out
native: false
scrollDraw checks once whether its options are native-eligible. If so it injects a stylesheet with keyframes and a view-timeline, and the browser updates the path from the scroll position with no JavaScript per frame; if not, an IntersectionObserver-gated requestAnimationFrame loop runs a callback before every frame. Both still paint on the main thread, so a long task delays frames either way.scrollDraw('#logo', options)nativeEligible()yesinject one <style>@keyframes + view-timelineon the container · returnnoIntersectionObservergates a rAF loop that setsstroke-dashoffset per pathmain thread · nativelong taskmain thread · JSlong task0 JS per framebrowser style + paint onlyJS every framea callback before each paint
Fig. 1 — the engine's real code path: one eligibility check at setup, then a generated stylesheet the browser runs from the scroll timeline, or a rAF loop that runs JavaScript before every frame
01The CSS primitive

What is animation-timeline: view()?

Scroll-Driven Animations is a CSS spec that lets you tie a CSS @keyframes animation to the scroll position of an element in the viewport — without any JavaScript. The browser drives it from the scroll position itself; no script runs per frame.

The key property is animation-timeline: view(). Combined with animation-range, you declare “play this animation as the element travels from X to Y in the viewport”. The browser scrubs the animation in sync with scroll — no rAF, no event listeners, no JavaScript execution per frame.

native-css-raw.css18 lines
/* Pure CSS scroll-driven animation */
@keyframes draw-path {
  from { stroke-dashoffset: var(--path-length); }
  to   { stroke-dashoffset: 0; }
}

path {
  stroke-dasharray:  var(--path-length);
  stroke-dashoffset: var(--path-length);

  animation-name:           draw-path;
  animation-timing-function: ease-out;
  animation-fill-mode:      both;
  animation-duration:       1s; /* ignored — scroll drives it */

  animation-timeline: view();   /* scroll-driven */
  animation-range: entry 20% exit 80%;
}

The catch: you have to know the path length upfront (to set --path-length), and older browsers — Safari before 26, Firefox before 159 — don't support it. That's where svg-scroll-draw comes in — it measures the length, injects the CSS, and runs the same draw on its JS engine where the browser has no scroll timelines.

02Under the hood

How svg-scroll-draw activates the native path

When you call scrollDraw(), the engine first checks whether the config is “native-eligible”. If it is and the browser supports animation-timeline: view(), it generates a <style> tag and injects the CSS keyframe animation — then returns. The JS rAF loop never starts.

If the browser doesn't support it (Safari before 26, Firefox before 159, Chrome before 115), the engine falls back to the full JS path transparently. Your code doesn't change. The animation looks identical.

Native CSS path

  • Driven by the browser’s scroll timeline
  • Zero per-frame JavaScript
  • No scroll event listeners
  • No requestAnimationFrame
  • Instant response to scroll direction changes

JS fallback path

  • IntersectionObserver gating
  • requestAnimationFrame loop
  • Runs only while visible
  • Same visual result
  • Full instance API works
  • Activates automatically wherever view() is missing
engine.ts (simplified eligibility check)21 lines
function isNativeEligible(options) {
  if (options.native === false)      return false; // explicit opt-out
  if (!CSS.supports('animation-timeline: view()')) return false;
  if (typeof options.easing === 'function') return false; // custom fn = JS
  if (!['linear', 'ease-in', 'ease-out', 'ease-in-out'].includes(options.easing))
    return false;                                  // spring / bounce / elastic = JS
  if (options.stagger !== 0)         return false; // stagger needs JS timing
  if (options.speed !== 1)           return false; // non-1 speed shifts the range
  if (options.delay > 0)             return false;
  if (options.repeat || options.once || options.autoReverse) return false; // loop/once logic = JS
  if (options.morphTo || options.waypoints) return false; // path interpolation = JS only
  if (options.velocityScale)         return false; // needs live velocity
  if (options.clip || options.axis !== 'y' || options.scrollContainer) return false;
  if (options.onProgress || options.onStart || options.onComplete ||
      options.onEnter || options.onLeave ||
      options.onEnterBack || options.onLeaveBack) return false; // callbacks need JS frames
  if (options.strokeColor || options.strokeWidth || options.fillOpacity) return false;
  if (options.trigger.start !== 'top bottom' ||
      options.trigger.end   !== 'bottom top') return false; // only the default maps to CSS `cover`
  return true; // ✓ hand off to CSS
}
03Eligibility

What triggers native vs JS?

The native path activates when all of these are true:

  • Browser supports animation-timeline: view() — Chrome and Edge 115+, Safari 26+, Firefox 159+. Older browsers fall back automatically.
  • No callbacks (onProgress, onStart, onComplete, onEnter, onLeave…) — Callbacks require a JS frame to fire. Declaring any callback forces the JS engine.
  • No stagger — stagger offsets individual paths by time fractions — CSS can't express per-path delays within a single view() range.
  • No morphTo, waypoints, velocityScale, repeat, autoReverse, delay or once — These features need frame-by-frame state management that CSS can't provide.
  • Named easing (not a custom function) — linear, ease-in, ease-out and ease-in-out have exact CSS equivalents. Spring/bounce/elastic and custom functions require JS.
  • speed === 1 (default) — Non-1 speed values shift the effective trigger range. This is trivial in JS but requires a CSS calc() trick that isn't worth the complexity.
  • The default trigger window — Only top bottom → bottom top maps onto the CSS cover range. A custom start or end keeps the JS engine.
  • Page scroll on the vertical axis, no clip reveal — The generated view-timeline follows the block axis of the page. scrollContainer, axis: 'x' and clip all stay on JS.
  • No animated colors or widths — strokeColor, strokeWidth, fillOpacity — all require per-frame interpolation.

To write the CSS yourself, the CSS scroll-driven animation generator builds animation-timeline rules with a fallback, and the SVG line drawing generator turns any SVG into a file that draws itself with no JavaScript.

04In practice

Native vs JS — the code is identical

You don't write different code for the native path. The engine decides. Here are examples that hit native, and examples that stay on JS:

Native path activated

logo.js8 lines
import { scrollDraw } from 'svg-scroll-draw';

// Simple logo reveal — native CSS wherever view() is supported
scrollDraw('#logo', {
  easing: 'ease-out',
  fade: true,
});
// → CSS animation-timeline injected, no JS loop
Logo.tsx11 lines
import { ScrollDraw } from 'svg-scroll-draw/react';

// React component — also hits native path
function Logo() {
  return (
    <ScrollDraw easing="ease-in-out" fade>
      <svg>…</svg>
    </ScrollDraw>
  );
}
// add once and it moves to the JS path (needs freeze logic)

JS path (by necessity)

chart.js28 lines
// onProgress callback → JS path (needs frame-by-frame)
scrollDraw('#chart', {
  easing: 'ease-out',
  onProgress: (alpha) => {
    counter.textContent = Math.round(alpha * 1000);
  },
});

// stagger → JS path (per-path offset timing)
scrollDraw('#diagram', {
  stagger: 0.15,
  easing: 'ease-out',
});

// spring easing → JS path (not a CSS timing function)
scrollDraw('#path', {
  easing: 'spring',
});

// custom trigger window → JS path (only the default maps to CSS cover)
scrollDraw('#logo', {
  trigger: { start: 'top 80%', end: 'top 20%' },
});

// Opt out explicitly
scrollDraw('#path', {
  native: false, // always use JS engine
});
05Browser support

Where native runs today

BrowserVersionPathNotes
Chrome115+native CSSFull support since Jul 2023
Edge115+native CSSSame engine as Chrome
Safari26+native CSSScroll-driven animations shipped in Safari 26
Firefox159+native CSSOn by default since 27 Oct 2026
Chrome Android115+native CSSFull mobile support
Safari iOS26+native CSSSame engine as Safari 26
Firefox Android159+native CSSFollows desktop Firefox
Older versions—JS fallbackJS fallback active — same result, no code changes
06Performance impact

What the native path saves

JavaScript animations run on the main thread. When your main thread is busy — parsing JS, running React reconciliation, handling events — the scroll animation stutters. The scroll event fires, the rAF fires, but the frame is delayed. That's why even well-optimised JS scroll animations can drop frames during page load or heavy interaction.

On the native path there is no JavaScript of ours in the frame at all: the browser maps the scroll position to the keyframes itself and redraws the stroke. That is less work than the JS path, and none of it competes with your own scripts. It is not free, though. Browsers composite transform and opacity off the main thread, but stroke-dashoffset is not one of those properties, so each frame still restyles and repaints the path on the main thread — a long task can still delay a frame, with no script of ours adding to it.scrollAnimate's native path for opacity and transform is the one that can run fully on the compositor.

ScenarioJSNative CSS
Heavy page loadThe scroll handler and rAF callback queue behind other scripts, so frames run lateNo script of ours runs per frame; a long task still delays the next paint
React re-rendersRe-renders and the animation callback compete for the same main threadNothing of ours competes per frame; only the browser’s own restyle and repaint remain
Many animated pathsOne rAF loop recomputes every path in JavaScript each frameThe browser animates each path from its keyframes; no JavaScript per path per frame
07Control

Opt-out and instance API

If you need to force the JS engine — for testing, for a polyfill, or because you're debugging — set native: false:

opt-out.js4 lines
scrollDraw('#logo', {
  easing: 'ease-out',
  native: false, // always use JS rAF engine
});

The full instance API — pause(), resume(), seek(), replay(), destroy() — works on both paths. The native path implements these by toggling animation-play-state and injecting inline offsets.

instance-api.js8 lines
const instance = scrollDraw('#logo', { easing: 'ease-out' });

instance.pause();              // pauses wherever it is
instance.resume();             // continues from same point
instance.seek(0.5);            // jump to 50% drawn
instance.replay();             // restart from 0
instance.destroy();            // remove all styles + observers
instance.getProgress();        // → 0–1
08Summary

TL;DR

  1. svg-scroll-draw automatically uses the native CSS path on Chrome and Edge 115+, Safari 26+ and Firefox 159+.
  2. The native path runs zero JavaScript per frame — no scroll listeners, no rAF.
  3. The JS fallback activates automatically on older browsers — same visual result.
  4. Any config that needs JS (callbacks, stagger, spring easing, repeat, velocityScale, a custom trigger window) stays on the JS engine.
  5. The vast majority of real-world logo reveals and path animations hit the native path.
  6. You don't write different code. The engine decides.

— / next

Try it yourself

Open DevTools → Performance while scrolling a svg-scroll-draw animation. On Chrome, you'll see zero main-thread JS per frame.

npm i svg-scroll-drawPlayground →← Blog

Star on GitHubFound this useful? A star helps others find it.

→Parts list

Keep reading

More from the blog