# requestAnimationFrame & VSync vs Scroll-Driven Animations

- **Canonical URL:** https://frontend.rocks/vs/requestanimationframe-vsync-vs-scroll-driven-animations/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** rAF scroll loops sample scrollTop on the main thread, while Scroll-Driven Animations bind timelines to scroll on the compositor.

## Comparison Matrix

| Dimension | requestAnimationFrame & VSync | Scroll-Driven Animations |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Experimental |
| **Domain** | Rendering Pipeline | Rendering Pipeline |
| **Mental Model** | requestAnimationFrame schedules callbacks right before the browser paints the next VSync frame, matching display refresh rates. | animation-timeline: scroll() and view() bind CSS and WAAPI animations directly to scroll progress on the Compositor Thread. |
| **Prerequisites** | Event Loop, Macrotasks, and Microtask Queue (rAF runs in the rendering step of the HTML event loop after tasks and microtasks.); Browser Rendering Pipeline (Critical Rendering Path) (Mutations inside rAF are batched directly into the upcoming Style/Layout/Paint cycle.) | Web Animations API (WAAPI) (Scroll-driven timelines plug into the same Web Animations timing model.); GPU Compositor Layers and will-change (Scroll progress updates on the Compositor Thread without main-thread scroll listeners.) |
| **When Not to Use** | When not to use requestAnimationFrame: Do not use rAF for simple transform or opacity transitions; use CSS transitions, the Web Animations API, or Scroll-Driven Animations so they run off the main thread. | When not to use Scroll-Driven Animations: Do not use them for critical navigation state or binary sticky-header triggers where IntersectionObserver or position: sticky suffices. |

## requestAnimationFrame & VSync — Under the Hood
Using `setInterval(fn, 16)` for animation is like mailing letters without checking when the postal truck leaves, some frames get two deliveries, others get zero. `requestAnimationFrame` hands your update directly to the driver as the truck pulls out.

1. **VSync Alignment**: The compositor signals `BeginMainFrame` in sync with the monitor's refresh rate (60Hz, 120Hz, or 144Hz).
2. **Queue Snapshotting**: The [Event Loop](/concepts/event-loop-tasks-microtasks) drains tasks, then runs every queued rAF callback for the current frame. Calls to `requestAnimationFrame` made inside a callback defer to the next VSync.
3. **Single Render Pass**: All DOM mutations inside rAF coalesce into one pass of the [Browser Rendering Pipeline](/concepts/browser-rendering-pipeline).

```js
let last = 0;
function tick(timestamp) {
  const dt = last ? (timestamp - last) / 1000 : 0;
  last = timestamp;
  box.style.transform = `translateX(${(timestamp * 0.08) % 300}px)`;
  if (dt < 1) requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
```

## Scroll-Driven Animations — Under the Hood
A JS scroll listener is a backseat driver shouting coordinates over a walkie-talkie; `animation-timeline` wires the speedometer directly to the axle.

1. **Timeline Replacement**: Instead of wall-clock time, [Web Animations API](/concepts/web-animations-api) timelines sample progress from `0%` to `100%` based on scroll offset.
2. **Compositor Execution**: When animating [GPU Compositor Layers](/concepts/gpu-compositor-layers) properties like `transform: scaleX()` or `opacity`, the Compositor Thread updates pixels without waking the main thread.
3. **Named Ranges**: `animation-range: entry 0% cover 40%` scopes `view()` animations to exact entry and exit phases.

```css
@supports (animation-timeline: view()) {
  .reveal-card {
    animation: fade-slide linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 80%;
  }
}
```

## Interactive Labs & Dissections
- [requestAnimationFrame & VSync Lab](https://frontend.rocks/concepts/requestanimationframe-vsync/#lab) ([Markdown](https://frontend.rocks/concepts/requestanimationframe-vsync.md))
- [Scroll-Driven Animations Lab](https://frontend.rocks/concepts/scroll-driven-animations/#lab) ([Markdown](https://frontend.rocks/concepts/scroll-driven-animations.md))

## Related Architecture Autopsies
- [Autopsy #09: 60 FPS on MacBook Pro, 11 FPS on Mid-Range Android](https://frontend.rocks/autopsies/mobile-scroll-jank-vram-explosion/) ([Markdown](https://frontend.rocks/autopsies/mobile-scroll-jank-vram-explosion.md)): A card grid scrolls at 60 FPS on MacBook Pro but stutters at 11 FPS and OOM-kills the browser tab on mid-range Android.

## Primary Sources
- https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animation-frames
- https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame
- https://drafts.csswg.org/scroll-animations-1/
- https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline
