Pixel Transition
A two-state surface that is its own trigger: 70 tiles in the color of the state to come land in random order, the state changes underneath, then they leave the way they came. 1.25 s in all, a different draw on every run, CSS grid and 2.9 KB of JavaScript.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →
3 usage examples



How it works
The .pxt-scene surface (300 × 220 px) stacks three layers: .pxt-dark at the bottom, .pxt-light above it but transparent, and a .pxt-grid of 10 columns by 7 rows on top. On load, the script fills that grid with 70 empty tiles (31 × 32.4 px, overlapping by half a pixel so that no seam shows between them). There is no separate button: the surface itself takes the click, Enter or Space.
On each trigger, the script reads in the CSS the background color of the layer to come and gives it to the 70 tiles, each with a random delay between 0 and 0.4 s. They fade in over 0.15 s, without growing or spinning. Readings: about 40% of the surface covered at 250 ms, all of it at 580 ms. At 600 ms, the .pxt-on class shows the other state under the tiles; at 650 ms they start to leave, with the same delays, so first in is first out. At 1,000 ms about a third is still there, at 1,250 ms none.
Because the tiles already wear the color of the next state, you never go through a black screen: the new state seems to land piece by piece, then its content is uncovered. During those 1.25 s, actions are ignored (two clicks 120 ms apart count as one): the transition always runs to its end, it cannot be reversed midway. The next click travels back with a new draw and tiles of the other color.
Accessibility
- Keyboard: the surface carries
role="button"andtabindex="0". Tab reaches it, Enter and Space trigger it, and Space does not scroll the page (reading: 0 px). 2 px grey outline, offset by 4 px, on keyboard focus. - Screen readers:
aria-pressedfollows the state, and at 600 ms the script swapsaria-hiddenbetween the two layers. So the button is named by the content of the state on screen, never by both at once. The grid is hidden at all times. - Reduced motion: the grid is removed (
display: none) and the two states swap right away, through a 150 ms fade (two thirds of the way after 60 ms). The toggle works, with no tile at all. - By finger: the target is the whole surface, 300 × 220 px in the demo. Nothing depends on hover.
- Content: since the surface acts as a button, put no link or field in it; a heading inside is no longer announced as a heading. Text, pictograms and images are fine.
Browser compatibility
CSS grid, inset and opacity transitions + 2.9 KB of JavaScript (70 elements created, getComputedStyle, three timers). Timeline, lock during the animation, keyboard, emulated touch, fifteen surfaces on one page and reduced motion give the same readings in Chromium 149, Firefox 151 and WebKit 26.5. CSS grid exists since Chrome 57, Firefox 52 and Safari 10.1; inset sets the floor, Chrome 87, Firefox 66, Safari 14.1. The custom focus outline needs Chrome 86, Firefox 85, Safari 15.4.
Without JavaScript, the surface stays on its first state and the grid stays empty. In a browser without inset, the layers no longer cover the surface: use top, right, bottom and left instead if you target older ones.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="pxt-stage">
<div class="pxt-scene" role="button" tabindex="0" aria-pressed="false">
<div class="pxt-dark">
<h3>…</h3>
<p>…</p>
<span class="pxt-badge">…</span>
</div>
<div class="pxt-light" aria-hidden="true">
<h3>…</h3>
<p>…</p>
<span class="pxt-badge">…</span>
</div>
<div class="pxt-grid" aria-hidden="true"></div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Tile color (CSS — background of .pxt-dark and .pxt-light) |
#18181b and #fafaf9 |
No separate setting: the tiles take the background color of the layer you are heading to. Change the layer's, they follow. |
Grid split (CSS — grid-template-columns and grid-template-rows of .pxt-grid) |
10 × 7 | As long as the product is 70, CSS is enough: 14 × 5 for a wide banner (checked, 22 × 45 px tiles on the demo), 7 × 10 for a portrait format. For another total, also change CELLS in the script. |
Spread of arrivals (JS — MAX_DELAY) |
0.4 s | Shorter, the tiles land almost together; longer, they trickle in. Then realign SWAP_AT (maximum delay + 0.15 s of fade, rounded up), UNCOVER_AT and END_AT, or the state changes before it is covered. |
Fade of one tile (CSS — transition: opacity .15s of .pxt-cell) |
0.15 s | 0s gives tiles that snap, LED-board style; .3s softens, provided you add the difference to the script's three instants. |
Surface size (CSS — .pxt-scene { width; height; border-radius }) |
300 × 220 px, 16 px corners | The grid is in fractions: it follows any size, from a 100 × 64 px square to a whole screen. |
FAQ
background-color, and nothing else. A layer dressed in a gradient alone has a transparent background color: the tiles are created, but invisible, and the state changes at once at 600 ms (checked in all three engines). Always give the layer a solid color under its image, for instance background: #143259 url(...): the tiles take that color, then uncover the image.pxt-on class on .pxt-scene in the HTML, nothing else. On load, the script reads that class, starts from the second state and sets aria-pressed and both aria-hidden values to match the screen itself; no transition plays on opening, and the first click goes back to the first state (checked in all three engines). This is how the bingo card in the example opens with three squares already marked.