A tiny 3x3 animated pixel grid indicator driven by simple delay arrays. Zero dependencies, under 3KB.
The pixel grid loading concept was originally created by SuCodee for Swift projects.
I first came across it through Kevin Grajeda via this post on X, which inspired this web implementation.
npm install MetaHeavies/3-pixel-grid
Copy dist/pixel-grid.js and dist/pixel-grid.css (or dist/pixel-grid.full.css for color variants) into your project.
<link rel="stylesheet" href="pixel-grid.css">
<div class="pixel-grid" id="my-grid"></div>
<script src="pixel-grid.js"></script>
<script>
PixelGrid.create(document.getElementById('my-grid'), {
animation: 'wave-lr'
});
</script><div class="pixel-grid" data-pixel-grid data-pixel-grid-animation="spiral-cw"></div>
<script>
PixelGrid.initAll();
</script>var grid = PixelGrid.create(element, {
animation: 'wave-lr', // preset name or custom object
autoplay: true // default: true
});
grid.play();
grid.stop();
grid.setAnimation('snake');
grid.destroy();Pass an object instead of a preset name:
PixelGrid.create(element, {
animation: {
name: 'my-pattern',
delays: [0, 100, 200, 300, 400, 300, 200, 100, 0],
duration: 200
}
});Animation format:
name(string) — identifierdelays(array of 9 numbers) — stagger delay in ms for each cell (left-to-right, top-to-bottom)duration(number) — hold time in ms before fade-out begins
Creates a new pixel grid instance inside the given DOM element.
Options:
| Key | Type | Default | Description |
|---|---|---|---|
animation |
string or object | 'wave-lr' |
Preset name or custom animation object |
autoplay |
boolean | true |
Start animating immediately |
Returns: Instance object with play(), stop(), setAnimation(anim), destroy(), getConfig().
Finds all elements with [data-pixel-grid] and creates instances. Returns an array of instances.
Returns an instance by its numeric ID.
Destroys all active instances.
Returns an array of all built-in preset names.
Returns a preset object by name, or null.
Direct access to the preset lookup object.
| Name | Description |
|---|---|
wave-lr |
Wave sweeping left to right |
wave-rl |
Wave sweeping right to left |
wave-tb |
Wave sweeping top to bottom |
wave-bt |
Wave sweeping bottom to top |
spiral-cw |
Clockwise spiral from top-left |
corners-first |
Corners light up first, then edges, then center |
center-out |
Center cell first, radiating outward |
diagonal-tl |
Diagonal sweep from top-left |
snake |
Snake path through the grid |
cross |
Cross/plus pattern |
checkerboard |
Alternating cells |
rain |
Random rain-like pattern |
pinwheel |
Rotating pinwheel |
orbit |
Orbiting pattern |
converge |
Corners and edges converge to center |
zigzag |
Zigzag path through cells |
Includes the grid layout, cell states, default cyan color, and reduced-motion media query. This is all you need.
Optional. Adds 12 color variant classes:
<div class="pixel-grid pixel-grid--magenta" data-pixel-grid></div>Available: cyan, magenta, yellow, green, orange, blue, red, purple, white, teal, pink, lime.
Core + colors combined in one file for convenience.
- Respects
prefers-reduced-motion: reduce— animations are disabled and cells show their "on" state statically - CSS transitions are removed under reduced motion
MIT