scroll-buddy: A Scroll-Driven Mascot Library on npm

An open-source npm package I published: a tiny mascot that follows a zig-zag trace down the page as you scroll. It walks, climbs, waves when you pause, drops a trail and makes elements react as it passes. It runs on this portfolio (Bit, a server bot) and on my Pith Shopify storefront (Pip, a citrus slice).

Open sourceJavaScript
Illustration of the scroll-buddy (npm) project
0
runtime dependencies
6.7 KB
gzipped
16
automated tests
3
builds: ESM, CJS, browser
Pip, a citrus slice mascot, rolling down a zig-zag trace on a Shopify storefront
Pip on the Pith storefront
Bit, a server bot, walking a zig-zag trace down this portfolio
Bit on this portfolio (scroll the home page to see it live)

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

  1. 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 getPointAtLength in the hot loop.

  2. 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.

  3. 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.

  4. 04

    Accessible by default

    Decorative and aria-hidden, never intercepts clicks, off for prefers-reduced-motion (and switches off live if the setting changes), and off on small screens.

  5. 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.

  6. 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.
MIT licensed. Install it with npm install scroll-buddy.

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

Related case studies

Shopify / Liquid / Theme developmentShopify Showcase

Pith: Playful Zero-Proof Drinks Storefront on Shopify

A bright, sticker-style brand store with personality: a peel-to-enter splash, a canvas slice-the-fruit mini game, reviews as a group chat, a drag-to-scroll photo strip, a merch drop grid and a small citrus mascot that rides a zig-zag line down the page, reacting to the content as it passes.

Read case study View store

Store password: yietha

Have a project like this in mind?

Tell me what you're building. I'll reply by email with questions or a suggested approach.