Scratch to Reveal
Web (React)
An interactive canvas component that lets users scratch off an overlay to reveal the content underneath.
A highly optimized HTML5 <canvas> interaction. As the user scrubs their mouse across the container, it visually erases the overlay and calculates the cleared percentage of the bounding box. Once the threshold is crossed, it snaps the rest of the overlay away.
🎉
You Won!
Enjoy your prize.
Installation
CLI
npx @modus-ui/cli add scratch-to-revealManual
- Copy the code from the component tab.
- Create a file at
components/ui/scratch-to-reveal.tsx. - Paste the code.
Usage
tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
width | number | - | Width of the scratch area in pixels. |
height | number | - | Height of the scratch area in pixels. |
brushSize | number | 40 | Radius of the scratch brush in pixels. |
threshold | number | 0.5 | Fraction cleared before the rest is revealed. |
overlayImage | string | - | Image drawn on the scratch surface. |
overlayColor | string | "hsl(var(--primary))" | Colour of the scratch surface when there is no image. |
Comments