Pixel UI/Delight/Scratch card

Scratch card

A scratch-off card: pixel foil over your content. Scratch it away.

<piix-scratch>DOM + canvas

Scratch the foil

You won 20% off

PIXEL20
Foil
Grain

Whatever is inside sits under a sheet of pixel foil with a sheen, a pattern and a label. Drag over it with a mouse, finger or pen and the foil comes off in pixel blocks, curling away as shavings that fall. Once most of it is gone, the rest flakes off by itself. Until then the content inside cannot be tabbed into; keyboard and screen-reader users get a real button that reveals it at once.

Installation

<!-- once, anywhere on the page: every component -->
<script src="https://cdn.jsdelivr.net/npm/piixpal@0.6/piixpal.min.js"></script>

Usage

<piix-scratch>
  <div style="padding:26px 32px;background:#fbf8f1;box-shadow:inset 0 0 0 3px #17121f;text-align:center;color:#17121f">
    <h3 style="margin:0 0 6px">You won 20% off</h3>
    <code style="font-size:28px;letter-spacing:.1em">PIXEL20</code>
  </div>
</piix-scratch>

Examples

Gold, for the big prize

FREE
shipping, forever

React to the reveal

Listen for reveal, or scratch to follow the progress.

Seat 14C

Scratch to find your seat.

API reference

AttributeWhat it doesDefault
foilsilver gold holo inksilver
labelthe text printed on the foilSCRATCH ME
grainthe size of one foil pixel, in px6
brushhow wide you scratch, in px22
revealhow much must be scratched before it all comes off, 0 to 1.55
soundmake sounds even without <piix-chiptune>; off keeps it silent–

Events

EventWhen
scratchfoil came off: detail.progress, 0 to 1
revealit is all off

Methods

MethodWhat it does
reveal()take all the foil off now
reset()put fresh foil back on

Accessibility