npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

frame-scroll-animation

v1.0.1

Published

A lightweight, dependency-free library for ultra-smooth scroll-driven canvas animations.

Downloads

185

Readme

Scroll Animation Renderer

A lightweight, dependency-free library for ultra-smooth scroll-driven canvas animations.

Features

  • 🎞 Frame-by-frame scroll animations using Canvas
  • 🖼 Image sequence support (PNG/JPG)
  • 🧩 Subframe extraction for large spritesheets
  • 🎬 MP4 decoding via the modern VideoDecoder API
  • ⚡ High performance thanks to ImageBitmap and caching
  • 📦 Zero dependencies
  • 🔌 Easy integration via a custom HTML tag: <scroll-animation>

Installation

npm

npm install your-package-name

CDN / Static

<script src="scroll-animation.js" type="module"></script>

Usage

  1. Add the custom element:

    <scroll-animation
        section-id="hero"
        animation-id="product-spin"
        host="https://your-host.com/animations">
    </scroll-animation>
  2. Create an animation.json alongside the frame assets:

product-spin/
├─ 0001.png
├─ 0002.png
├─ ...
└─ animation.json

Example animation.json:

[
  {
    "imageSrcUrl": "",
    "imgSize": [1920, 1080],
    "numFrames": 120,
    "files": [".png"],
    "numSourceFiles": 120,
    "reverse": false
  }
]

This configuration describes how the animation should be loaded and rendered.

Folder Structure (example)

my-app/
├─ animations/
│  └─ product-spin/
│     ├─ 0001.png
│     ├─ 0002.png
│     ├─ ...
│     └─ animation.json
├─ src/
│  └─ main.js
└─ index.html

How it Works

The library:

  • Loads all image frames or decodes video frames
  • Splits render files into subframes if needed
  • Sorts and caches frames globally
  • Maps scroll position → frame index
  • Renders the selected frame to a <canvas> inside your <scroll-animation> element

Frame Calculation

getFrameIndex() {
  const currentScrollPosition =
    (-this.scrollSection.getBoundingClientRect().top) /
    ((this.height - this.canvasElement.clientHeight) - window.innerHeight);

  return Math.round(currentScrollPosition * this.numFrames);
}

MP4 Video Support

If your animation is a single .mp4 file, the library uses the VideoDecoder API:

const videoDecoder = new VideoDecoder({
  output: (frame) => {
    createImageBitmap(frame).then((bitmap) => {
      bitmap.index = images.length;
      images.push(bitmap);
    });
  },
  error: console.error
});

This lets you deliver high-quality scroll animations without storing hundreds of images.

Example Demo

<section id="hero" style="height: 300vh;">
    <scroll-animation
        section-id="hero"
        animation-id="product-spin"
        host="/animations">
    </scroll-animation>
</section>

<script type="module">
    import './scroll-animation.js';
</script>

Options (from animation.json)

| Key | Type | Description | |-----------------|------------|---------------------------------| | imageSrcUrl | string | Base path for frames | | imgSize | [w,h] | Frame width & height | | numFrames | number | Total frames | | numSourceFiles | number | Number of source files | | files | string[] | Filenames or extension | | reverse | boolean | Play animation backwards | | range | [a,b] | Scroll range control | | id | string | Cache identifier |

Custom Element API

Your <scroll-animation> tag supports these attributes:

| Attribute | Purpose | |---------------|-------------------------------------------| | section-id | Section tied to the scroll position | | animation-id | Folder name / animation config identifier | | host | Server location of your animation assets |

Example:

<scroll-animation section-id="intro" animation-id="car" host="/assets/animations"></scroll-animation>

Development

Build and test commands depend on your project setup; add more if needed.

npm run dev
npm run build

Contributing

Contributions, issues, and feature requests are welcome — feel free to open a PR or start a discussion.

License

MIT License — free to use, modify, and distribute.

Support

If you find this library useful, please consider:

  • ⭐ Starring the repo
  • 🐛 Reporting issues
  • 💬 Suggesting new features