StealThis .dev

Scratch to Reveal

Interactive scratch card effect where users drag to erase an overlay and reveal hidden content underneath.

Labで開く
css javascript vue svelte
ターゲット: TS JS HTML React Vue Svelte

コード

Scratch to Reveal

An interactive scratch card effect using HTML Canvas. Users drag their mouse or finger across a canvas overlay to erase it, gradually revealing hidden content underneath.

How it works

  1. A <canvas> element is positioned over the hidden content
  2. The canvas is filled with a solid overlay color
  3. On mouse/touch drag, globalCompositeOperation: 'destination-out' erases the overlay
  4. Drawing uses round line caps for smooth, natural-looking scratches
  5. When a percentage threshold is reached, the full content is revealed

Customization

  • Set overlayColor to change the scratch surface color
  • Adjust brushSize for wider or narrower scratch strokes
  • Configure revealThreshold (0-1) for when the full auto-reveal triggers
  • Add custom content as children/underneath the canvas

When to use it

  • Promotional reveals (discount codes, prizes)
  • Gamification elements
  • Interactive onboarding steps
  • Hidden content teasers