useScrollDraw hook · createScrollDraw

Solid.js scroll animation

Solid’s fine-grained reactivity means an animation library must not force re-renders to move a value, and this one does not — the draw runs outside the reactive graph entirely, driven by scroll position. The example animates a signal feeding two memos into an effect, which is a fitting subject: the diagram explains the model the code is written in.

The code

A fine-grained reactivity graph — createSignal feeding two createMemo derivations into a createEffect — animates with ease-out on scroll. Uses the useScrollDraw hook; createScrollDraw gives access to the instance for replay and pause.

Hero.tsx
// Option 1: useScrollDraw hook (simplest)
import { useScrollDraw } from 'svg-scroll-draw/solid';

function Hero() {
  const ref = useScrollDraw({
    easing: 'ease-out',
    fade:   true,
    once:   true,
  });
  return (
    <div ref={ref}>
      <svg viewBox="0 0 200 80" fill="none">
        <path d="M10 40 Q100 5 190 40"
          stroke="#446B9E" stroke-width="2.5" />
      </svg>
    </div>
  );
}

// Option 2: createScrollDraw — instance control
import { createScrollDraw } from 'svg-scroll-draw/solid';

function HeroWithReplay() {
  const { ref, getInstance } = createScrollDraw({
    easing: 'spring',
    once:   true,
  });
  return (
    <>
      <div ref={ref}>
        <svg viewBox="0 0 200 80" fill="none">
          <path d="M10 40 Q100 5 190 40"
            stroke="#446B9E" stroke-width="2.5" />
        </svg>
      </div>
      <button onClick={() => getInstance()?.replay()}>
        Replay
      </button>
    </>
  );
}

Live — scroll it

Solid.js
createSignalcount = 0createMemodoubledcreateMemoisEvencreateEffectDOM update

Install

terminal
npm i svg-scroll-draw

MIT licensed, zero runtime dependencies. Every API is a separate entry point, so you only ship what you import. Full API reference →