---
name: scroll-effects
description: Use when building scroll-linked effects such as reveals, parallax, sticky storytelling, progress indicators or headers that shrink, preferably with CSS scroll-driven animations.
---

# Scroll effects

Scroll effects should help people follow a story or keep context. They must never block scrolling or hide content.

## Prefer CSS scroll-driven animations

They run off the main thread and need no JavaScript.

```css
@supports (animation-timeline: view()) {
  .reveal {
    animation: reveal linear both;
    animation-timeline: view();
    animation-range: entry 10% cover 30%;
  }
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
```

- `view()` tracks an element crossing the viewport; `scroll()` tracks a scroller's progress.
- Use `animation-range` to decide exactly when an effect starts and ends.
- Use `linear` easing; the scroll position is the easing.

## Common recipes

- **Reading progress bar**: `scaleX` from 0 to 1 on `animation-timeline: scroll(root)`.
- **Shrinking header**: scale the avatar and title down over the first 120-200px of scroll.
- **Sticky story**: a `position: sticky` stage inside a tall section; swap content with ranges.
- **Parallax**: move background layers at 10-30% of scroll speed, never the text.

## JavaScript fallback

Use `IntersectionObserver` for one-off reveals and GSAP ScrollTrigger or Framer Motion `useScroll` only when CSS cannot do it. Throttle work to `requestAnimationFrame`.

## Rules

- Content must be readable with animations disabled; animate from a visible state when possible.
- Never hijack or smooth the native scroll by default.
- Avoid scroll-linked effects on long forms and data pages.
- Reduced motion: show the final state immediately.
