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:
Installation
$3
``
npm install your-package-name
`
$3
`
`
Usage
1. Add the custom element:
`
html
section-id="hero"
animation-id="product-spin"
host="https://your-host.com/animations">
`
2. Create an
animation.json
alongside the frame assets:`
product-spin/
āā 0001.png
āā 0002.png
āā ...
āā animation.json
`
Example
animation.json
:`
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