The challenge
Scroll-driven mascots are a lovely touch of personality, but most implementations are one-off, tied to a single site, heavy, or careless about accessibility and performance.
I wanted a reusable package that is dependency-free, cheap per frame, safe to import in any framework and respectful of visitors who prefer reduced motion.
How I approached it
- 01
Sample the path once
A smooth zig-zag is generated as cubic curves and sampled once into an evenly spaced lookup table. Each scroll frame is just a table read and one transform write, with no
getPointAtLengthin the hot loop. - 02
Pure, tested core
Path sampling, scroll progress, the walk/climb/wave state machine and the swept-box collision test are pure functions, unit-tested without a browser. A jsdom suite covers mounting, cleanup, scrolling and reactions.
- 03
Reactions that never miss
Elements react as the mascot passes. The test covers the whole span travelled between frames, so a fast flick still connects, with a one-shot latch per element per pass.
- 04
Accessible by default
Decorative and
aria-hidden, never intercepts clicks, off forprefers-reduced-motion(and switches off live if the setting changes), and off on small screens. - 05
Works anywhere
Framework-free with ESM, CJS and an IIFE build, SSR-safe, TypeScript declarations included, and a documented option to avoid injected styles under a strict CSP.
- 06
Characters are data
Pip and Bit are just three SVG strings each. Anyone can pass their own character and colour it through CSS variables.
Deliberate trade-offs
- Version 1 follows the window scroll only. A custom scroll container would need a different progress source.
- It is decoration, so it deliberately disappears on small screens and for reduced-motion visitors.
What I built
- Designed the API, the path generator and sampler, the pose state machine and the collision logic.
- Drew the two built-in characters (Pip and Bit) with walk, climb and wave poses.
- Wrote 16 unit and integration tests and a build that outputs ESM, CJS, an IIFE bundle and a stylesheet.
- Published the package to npm, wrote the documentation and recorded demo GIFs from real sites.
- Used it in production on this portfolio and on a Shopify storefront.
What this project demonstrates
- Publishing and maintaining an open-source npm package end to end
- Performance-minded animation and testable logic
- Accessibility, CSP and SSR awareness in a front-end library
- Clear documentation and developer experience



