Installation
Usage
import { DitherLens } from "@/components/dither-lens"
export function Hero() {
return (
<DitherLens text="Signal." y={0.42} className="flex min-h-[32rem] flex-col items-center justify-end px-6 pb-12 text-center">
<p className="text-muted-foreground">Move your pointer to see through.</p>
</DitherLens>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | "Signal." | The headline in the picture, in your page's font. Also real text on the page, for screen readers and search engines. |
| src | string | — | A photo to dither instead of the headline (same origin or served with CORS). |
| colors | [string, string] | ["var(--background)", "var(--primary)"] | The two inks, dark then light. Any CSS colour. |
| pattern | "bayer" | "dots" | "lines" | "bayer" | An ordered dither, newspaper dots, or engraved lines. |
| cell | number | 4 | Size of one dot, 2–12 CSS pixels. |
| size | number | 1 | Size of the lens, 0.5–1.6. |
| y | number | 0.45 | Where the headline sits, from 0 (top) to 1 (bottom). |
| autoplay | boolean | true | When nobody is near, the lens wanders slowly over the picture. |
| interactive | boolean | true | The lens follows the pointer on a spring; pressing opens it wider. |
| moment | number | — | Holds the lens still where it wanders to at this moment, in seconds. |
| captureRef | Ref<DitherLensHandle> | — | capture(width, height) resolves a PNG at any size: wallpapers, social cards, a 4K hero. |
| ...props | HTMLAttributes<HTMLDivElement> | — | Children sit above the picture and stay interactive. |
Accessibility
- The headline is real text in the page (visually hidden), so screen readers and search engines read it; the canvas and its still are decorative and hidden from assistive technology.
- With prefers-reduced-motion the lens rests over the headline, the dots stay still and the pointer is ignored.
- It pauses off-screen and in hidden tabs, and frees its GPU memory when removed.
- Without WebGL2, on a software renderer, or on a device that can't hold a smooth frame rate, it shows the picture without the effect.
Changelog
- v1.0.0Latest
First release.