Pixel UI/Physics & time/Sand

Sand

Your text crumbles into sand, piles up, and flows back into words.

<piix-sand>DOM + canvas

Brush over the words

Touch these words.

Brush over a line and it falls apart, pours down and piles up on the words below. Stop, and every grain flies home.

Sand piles on me
Trigger
Grain
Flows back after

Every letter inside is redrawn as pixels, and every pixel is a grain in a real falling-sand simulation. Brush over a word and its grains come loose: they pour down, slide off each other into piles, land on the words below and on buttons and images (those stay solid), and you can sweep the piles around with the pointer. Stop for a moment and every grain flies back to the exact pixel it came from, and the real text returns. Your markup is never changed: the words stay in the page the whole time, for selection, search and screen readers.

Installation

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

Usage

<piix-sand>
  <h2 class="ex-h2">Touch these words.</h2>
  <p>Brush over a line and it falls apart, pours down and piles up on the words below. Stop, and every grain flies home.</p>
  <piix-button tone="ink">Sand piles on me</piix-button>
</piix-sand>

Examples

Click to collapse

With trigger="click" one click brings it all down; with rest="never" it stays down until the next click.

Click me.

Once to bring it down, again to build it back.

Around images

Images, buttons, inputs and anything with data-solid stay put, and the sand piles on them.

Patch notes

Brush the words to the right of the picture and watch them pour down its edge and heap on the button below.

Grains that land on letters rest on them, and fall again when those letters crumble too.

Read more

From your own code

crumble() brings everything down, crumble(x, y, r) just one spot, rebuild() calls it home.

Crumble Rebuild

API reference

AttributeWhat it doesDefault
triggerbrush: the pointer crumbles what it touches. click: a click brings it all down. none: only from codebrush
brushthe brush's radius, in px22
grainthe size of one grain, in px2
restseconds of calm before it flows back, or never2
soundmake sounds even without <piix-chiptune>; off keeps it silent–
data-solidon any element inside: it stays solid and sand piles on it (images, buttons and inputs already do)–

Events

EventWhen
crumblethe first grains come loose
rebuildevery grain is home and the real text is back

Methods

MethodWhat it does
crumble()bring everything down
crumble(x, y, r)crumble one spot: x and y in px from its top-left, r the radius
rebuild()send every grain home now

Accessibility