22 / blog / performanceJune 20268 min read

Scroll animation performance: native CSS vs JavaScript

Most scroll animation libraries run JavaScript on every scroll event. svg-scroll-draw takes a different approach: use the browser's native animation-timeline: view() when possible — no per-frame JavaScript — and fall back to a lean JS engine when it’s not.

  • Performance
  • animation-timeline
  • Scroll timeline
  • rAF
Native path
zero JS
JS engine
IO + rAF
Eligibility checks
9
Frame budget
16.7 ms

JS engineIntersectionObserver + rAF

Main thread
compositor

Native pathanimation-timeline: view()

Main threadidle — no listener, no rAF, no style writes
compositor
  • rAF callback — read scroll, el.style.setProperty()
  • Style recalc
  • animate opacity / transform + composite
  • frame boundary — 16.7 ms at 60 fps
Fig. 1 — where the per-frame work runs for an opacity / transform animation, as a Performance-panel trace — three frames at 60 fps; block widths schematic. SVG strokes skip the script but still restyle and paint on the main thread.
01The problem

The problem with JS scroll listeners

Traditional scroll animation libraries work by listening to the scroll event, reading the scroll position, and then updating element styles in response. This runs on the main thread, competing with layout, paint, and user input.

Even with passive: true and requestAnimationFrame, any JS on the scroll path adds latency. On low-end mobile, this is the difference between smooth 60fps and visible jank.

02animation-timeline

The native CSS fast path

CSS Scroll-Driven Animations (animation-timeline: view()) map scroll to the animation inside the browser, with zero JavaScript involvement: no scroll listeners, no rAF, no per-frame objects for the garbage collector. For opacity and transform the browser can also run the animation on the compositor, off the main thread. Other properties — colours, an SVG stroke’s stroke-dashoffset— still restyle and repaint on the main thread each frame, only without a script.

Supported in Chrome and Edge 115+, Safari 26+, and Firefox 159+ (on by default since October 2026).

native-css.css14 lines
/* What the browser generates under the hood */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(32px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate {
  animation-name:            fadeUp;
  animation-duration:        auto;         /* scroll-driven */
  animation-timing-function: ease-out;
  animation-fill-mode:       both;
  animation-timeline:        view();       /* tied to scroll */
  animation-range:           cover 0% cover 100%;
}
03Eligibility

How svg-scroll-draw picks the right engine

svg-scroll-draw checks a set of eligibility criteria on every scrollAnimate call. If all pass, it injects a <style> tag and adds a class — no JS scroll listeners at all.

ConditionNative pathJS engine
Browser supports animation-timeline: view()—fallback
axis: "y" (vertical)
No custom scrollContainer
String easing (ease-out etc.)
No callbacks (onEnter, onComplete…)
Default trigger (top bottom → bottom top)
speed: 1
once: false
Safe CSS prop (opacity, transform, color…)
app.js20 lines
import { scrollAnimate } from 'svg-scroll-draw';

// Native CSS path: zero JS scroll listeners
scrollAnimate('#hero', {
  props:  { opacity: [0, 1], transform: ['translateY(32px)', 'translateY(0)'] },
  easing: 'ease-out',
  // native: true is the default
});

// JS engine: callbacks need main-thread JS
scrollAnimate('#section', {
  props:   { opacity: [0, 1] },
  onEnter: () => nav.setActive('section'),  // needs JS
});

// Force JS engine explicitly
scrollAnimate('#card', {
  props:  { opacity: [0, 1] },
  native: false,
});
04Fallback

The JS engine — when it runs

When the native path isn't eligible, svg-scroll-draw uses an IntersectionObserver to start/stop a requestAnimationFrame loop only while the element is in the viewport. The rAF loop stops completely when the element scrolls out — no wasted work.

CSS property updates are batched per frame via el.style.setProperty() — a single style recalc per element per frame.

05Checklist

Performance tips

  1. 01Stick to native-eligible configs opacity and transform are the properties browsers can composite: on the native CSS path they can run off the main thread entirely. Colours and SVG strokes still restyle and repaint on the main thread each frame — just without any JavaScript. Avoid animating layout-triggering properties (width, height, top, left) even in the JS engine.
  2. 02Use once: true for reveal animations Reveal animations that reverse on scroll back keep the rAF loop running. once: true freezes the final value and stops the loop after completion.
  3. 03prefers-reduced-motion is respected automatically svg-scroll-draw checks window.matchMedia("(prefers-reduced-motion: reduce)") and applies the final state immediately — no animation, full accessibility.
  4. 04Trigger windows matter A trigger from top-bottom to bottom-top means the animation is active the entire time the element is in view. Narrow triggers (e.g. top 80% to top 40%) run the rAF loop for less time.
→Parts list

Keep reading

More from the blog