Skip to content
Pixelbits
Docs / Pixel image reveal
Signature

Pixel image reveal

An image that resolves from a coarse pixel mosaic to sharp, in a few stepped frames. One <canvas> over a normal <img> (so the image keeps its alt text, lazy loading and SEO); the canvas only draws and never reads pixels, so cross-origin images work. With reduced motion the image just appears.

Sunset over hills
Sunset, revealed on hover

Installation

npm: import
import { PixelImageReveal } from "pixelbits/image-reveal";
shadcn: copy the source
npx shadcn add https://pixelbits.ali-moradi-develop.com/r/image-reveal.json

API

<PixelImageReveal>

An image that resolves from a coarse pixel mosaic to sharp, in a few stepped frames. One <canvas> over a normal <img> (so the image keeps its alt text, lazy loading and SEO); the canvas only draws and never reads pixels, so cross-origin images work. With reduced motion the image just appears.

Example
<PixelImageReveal src="/work/noir.jpg" alt="Atelier Noir home page" wrapperClassName="aspect-4/5" />
PropTypeDefaultDescription
src*string—

Image URL.

alt*string—

Alternative text, as for any image (empty for decorative ones).

trigger"view" | "hover""view"

When the reveal runs: when the image scrolls into view, or on hover and focus of the image's container (it then goes back to the mosaic).

stepsnumber[][32, 16, 8, 4]

Block sizes in px, from coarse to fine, before the sharp image.

durationnumber600

Total duration of the reveal in ms.

wrapperClassNamestring—

Classes for the wrapper (size it here; the image covers it).

Also accepts every prop of ImgHTMLAttributes<HTMLImageElement>.