Getting started

Create a scroll-driven story with a few scene definitions. You control the content and styling; ScrollDirector connects the timeline to scrolling.

Installation

Install ScrollDirector in your application directory.

Terminal
npm install scroll-director

React 18 and 19 are supported as optional peer dependencies. The main package does not import React.

You can also download the v0.1.0 package archive and install it with npm install ./scroll-director-0.1.0.tgz.

Without a package manager

Download the browser bundle for a complete HTML example, stylesheet, library and sample landscape assets. Extract the archive and open it through your existing HTTP server.

index.html
<link rel="stylesheet" href="./lib/scroll-director.css" />
<script src="./lib/scroll-director.browser.js"></script>

Create your first story

Import components from scroll-director/react and include the stylesheet once. In Next.js, put this code in a Client Component.

Story.tsx
import { Director, Scene, Camera, Layer } from "scroll-director/react";
import "scroll-director/style.css";

export default function Story() {
  return <Director>
    <Scene id="intro" duration={1600}>
      <Camera zoom={[1, 1.2]} />
      <Layer animate={{ y: [40, -40], opacity: [1, 0] }}>
        <h1>Let the story unfold.</h1>
      </Layer>
    </Scene>
    <Scene id="chapter-two" duration={1200} transition="dissolve">
      <Layer><h2>A new perspective.</h2></Layer>
    </Scene>
  </Director>;
}

Each Scene is a direct child of Director. A scene can contain layers and one camera. Give scenes an explicit id when you need to navigate to them.

Scene content is ordinary HTML. Style your text, images and inner elements as usual. The library owns the outer animation wrappers.

Understand scroll and timing

duration is a distance in CSS pixels. A scene with a duration of 1,600 progresses from 0 to 1 as the visitor scrolls 1,600 pixels.

First scene1,600 px
Dissolve300 px
Second scene1,200 px

The example above uses 3,100 pixels in total. During the transition, the outgoing scene holds at progress 1 and the incoming scene at progress 0. The second scene’s own animations begin after the transition finishes.

Reverse scrolling, jumping to an anchor and reloading at depth all derive their state from the current scroll position. There is no separate playhead to get out of sync.

Add layers and a camera

Use depth for vertical parallax. A value of 1 moves a layer upward by 25% of the stage height over the scene. Smaller values move it less.

Layer motion
<Camera zoom={[1, 1.2]} rotate={[0, 3]} />
<Layer depth={0.3} animate={{ x: [0, 80] }}>
  <img src="/mountains.svg" alt="" />
</Layer>

A camera transforms the whole scene. A layer transforms its own contents. Positions use pixels, rotation uses degrees and zoom uses a scale factor. For example, 1.2 means 120%.

Array values are evenly spaced keyframes. Use { values, offsets, easing } when you need precise timing. See the keyframe reference.

Keep your own transforms inside.

The engine writes transform, opacity and filter on its wrappers. Apply your own transforms to a child element so the two can compose.

Respect reduced motion

By default, ScrollDirector follows prefers-reduced-motion. Scenes return to normal document flow, all content stays readable and pinning, parallax and camera motion are disabled.

Inactive animated scenes are inert and hidden from assistive technology. Keyboard and touch scrolling remain native. Navigation does not forcibly move focus; your chapter controls can add an appropriate focus policy.

To preview the static layout, set reducedMotion="always" on Director, or use the reduced-motion switch on the examples page.

Use it under a subpath

When your application is hosted under a path such as /my-project/, image and script URLs must include that base path or use relative URLs. ScrollDirector itself does not fetch assets or require a particular host.

Keep the stylesheet and browser bundle alongside the application’s static files. An image-only DOM story does not need workers, a backend or an upload endpoint.