framework / solid.jsSolid 1.x · SolidStart
Solid.js scroll animations. Outside the reactive graph.
Solid’s performance story depends on not re-rendering, so an animation library that pushed a signal update every frame would undo the thing you picked Solid for. This one never touches the reactive graph: the engine writes to the DOM directly, driven by scroll position, and the hook only hands you a ref setter.
- solid entry
- 14.8 KB
- Every API
- 11.9 KB
- GSAP stack
- 47.5 KB
- Version
- 2.31.0
Quick start
Import from svg-scroll-draw/solid — every sample below is written against the wrappers this package actually exports.
Or start from a running project: the Solid.js starter on StackBlitz ↗ opens in the browser with nothing to install: a line drawing, words on scroll, a fade-in and a counter.
sample 01Hero.tsx
The hook — returns a ref setter
Hero.tsximport { useScrollDraw } from 'svg-scroll-draw/solid'; export function Hero() { // Returns a callback ref — pass it straight to ref={} const draw = useScrollDraw({ easing: 'ease-out', speed: 1.2, fade: true }); return ( <div ref={draw}> <svg viewBox="0 0 200 100"> <path d="M10 50 Q 100 10 190 50" stroke="#111" fill="none" /> </svg> </div> ); }sample 02Replayable.tsx
When you need the instance
Replayable.tsximport { createScrollDraw } from 'svg-scroll-draw/solid'; export function Replayable() { const { ref: draw, getInstance } = createScrollDraw({ easing: 'ease-out' }); return ( <> <div ref={draw}> <svg viewBox="0 0 200 100"> <path d="M10 50 Q 100 10 190 50" stroke="#111" fill="none" /> </svg> </div> <button onClick={() => getInstance()?.replay()}>Replay</button> </> ); }sample 03Stats.tsx
Text, counters and any CSS property
Stats.tsximport { useScrollAnimate, useScrollCounter, useScrollText } from 'svg-scroll-draw/solid'; export function Stats() { const card = useScrollAnimate({ props: { opacity: [0, 1], transform: ['translateY(24px)', 'translateY(0px)'] } }); const revenue = useScrollCounter({ to: 48000 }); const heading = useScrollText({ split: 'words', stagger: 0.05 }); return ( <> <h2 ref={heading}>Every API, one package.</h2> <div ref={card}><span ref={revenue}>0</span></div> </> ); }
The hook returns a callback ref rather than a signal, which is why you pass it directly to ref={} with no parentheses. Cleanup runs through onCleanup, so it works inside <Show> and <For> without leaking.
Pass a function, not an object
useScrollDraw({ speed: speed() }) calls the signal once, while the component function runs, and nothing reads it again: a later setSpeed(2) never reaches the drawing. Pass a function instead, useScrollDraw(() => ({ speed: speed() })). The hook calls it inside a createEffect, so the signal becomes a dependency, and a new value destroys the engine and starts another with the new options.
The browser suite runs this in a real Solid root: with the page held at one scroll position, setting the signal from 1 to 2 takes the path from half drawn to fully drawn. Read props the same way, inside the function. Destructuring them in the component body reads them once, like the object form.
A props object also works passed as it is, because Solid props are getters and the hook reads every property inside its effect. That includes children: the effect reads it each time it runs, and reading JSX children in Solid builds them again, as nodes nothing inserts. Split children, and any other prop that is not an option, off with splitProps first.
import { splitProps, type JSX } from 'solid-js';
import { useScrollDraw, type ScrollDrawOptions } from 'svg-scroll-draw/solid';
type Props = ScrollDrawOptions & { children: JSX.Element };
export function Drawn(props: Props) {
// `options` keeps Solid's getters, so the hook sees prop changes.
const [local, options] = splitProps(props, ['children']);
const draw = useScrollDraw(options);
return <div ref={draw}>{local.children}</div>;
}
// <Drawn speed={speed()} easing="ease-out"><svg>...</svg></Drawn>An equal re-run keeps the engine
The effect re-runs whenever a signal the function read changes, even when the options come out the same. Before rebuilding, it turns them into a fingerprint with optionsKey and compares it with the one the running engine was built from. If they match it returns, and the drawing carries on from where it is.
Functions count only as present or absent. A fresh onComplete arrow on every run is not a change, and the engine still calls the newest one, because it is handed wrappers that look the function up on the latest options.
The engine itself is built inside untrack. Whatever it reads while starting, your callbacks included, does not become a dependency of the effect, so the effect re-runs only for what your options read.
import { createSignal, Show } from 'solid-js';
import { useScrollDraw } from 'svg-scroll-draw/solid';
export function Signature(props: { speed: number }) {
const [done, setDone] = createSignal(false);
const draw = useScrollDraw(() => ({
speed: props.speed, // a dependency: a change rebuilds
onComplete: () => setDone(true), // a new arrow each run: no rebuild
}));
return (
<>
<div ref={draw}>
<svg viewBox="0 0 240 80" fill="none" stroke="#111">
<path d="M10 60 C 30 10, 50 10, 60 45 S 90 75, 110 40 S 150 15, 170 50 S 220 60, 230 30" />
</svg>
</div>
<Show when={done()}><p>Signed.</p></Show>
</>
);
}Call the hook where the element lives
onCleanup attaches to the owner that is running when the hook is called, normally the component. When Solid disposes that owner the engine is destroyed. The browser suite disposes a real createRoot and checks that no IntersectionObserver and no animation frame is left running.
So call the hook inside the component that <Show> or <For> creates, not in its parent. The ref setter only stores the node, and the effect starts the engine on its first run, after the component has rendered and ref has been set. A node that a <Show> in the same component adds later is stored but not started until the effect runs again, which with a plain object is never. A node it removes keeps its engine until that component is disposed.
Each hook has a create twin (createScrollDraw, createScrollAnimate, createScrollCounter, createScrollText, createScrollVideo) that returns { ref, getInstance }, an object rather than a pair. getInstance() is undefined until the effect starts an engine, and again after cleanup. After a rebuild it returns the new engine, so call it at the moment you use it rather than storing what it returned once.
import { createSignal, Show } from 'solid-js';
import { createScrollDraw } from 'svg-scroll-draw/solid';
function Diagram() {
// Owned by Diagram, so hiding it in <Show> destroys the engine.
const { ref, getInstance } = createScrollDraw({ preset: 'sketch' });
return (
<>
<div ref={ref}>
<svg viewBox="0 0 220 80" fill="none" stroke="#111">
<rect x="10" y="20" width="60" height="40" />
<path d="M70 40 H 150" />
<rect x="150" y="20" width="60" height="40" />
</svg>
</div>
<button onClick={() => getInstance()?.seek(1)}>Show all</button>
</>
);
}
export function Panel() {
const [open, setOpen] = createSignal(false);
return (
<>
<button onClick={() => setOpen((o) => !o)}>Diagram</button>
<Show when={open()}>
<Diagram />
</Show>
</>
);
}Size
svg-scroll-draw/solid is 14.8 KB gzipped, the engines it wraps included.
Measured 2026-08-14 at gzip level 9 against gsap 3.15.0 and svg-scroll-draw 2.31.0. Full comparison →
Solid.js questions
How do I animate on scroll in Solid.js?
Import useScrollDraw from svg-scroll-draw/solid. It returns a callback ref you pass directly to ref={} on the element wrapping your SVG. The animation runs outside Solid’s reactive graph, so it triggers no re-renders.
Does it cause re-renders in Solid?
No. The engine writes to the DOM directly rather than updating a signal each frame, so no reactive computation is invalidated by the animation. Only the elements being animated change.
Does it work with SolidStart and SSR?
Yes. Initialisation happens inside onMount, so nothing runs during server rendering, and onCleanup destroys the instance when the component unmounts.