TransitionsPremium

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.

CSSJSPixel

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

Village square message board, two messages on rotation — preview in the town hall's tool — Pixel Transition example 1

① Village square message board, two messages on rotation — preview in the town hall's tool

WhenThe town clerk programs the board on Market square: the Christmas market in amber on black, then the tree collection in black on amber. The preview plays the rotation as it will look outside: amber slabs take over the board, the second message appears underneath.
WhyOn an LED board, a crossfade gives an unreadable orange mush. Here each slab is either one color or the other, and neither text ever blends into the other.
Settings492 × 212 px .pxt-scene, 6 px corners; #0c0c0d background for one layer, #ffb000 for the other, which gives amber tiles on the way out and black ones on the way back. The fine mesh laid on top is a pseudo-element of the scene. In the capture, the scene clicks the surface twice by itself; on a real board, a timer would make that click.
Bingo card whose numbers you mark — a neighbourhood club's online bingo night — Pixel Transition example 2

② Bingo card whose numbers you mark — a neighbourhood club's online bingo night

When28 has just been called. The player clicks square 28 on her card: it fills with small orange tiles and comes back labelled "marked". At 63, same gesture. Wrong square? A second click unmarks it the same way.
WhyOn fifteen tight squares, the one that pixelates confirms which just changed, and it takes a good second to flip: enough not to mark twice by accident.
SettingsFifteen 100 × 64 px .pxt-scene surfaces in a CSS grid, that is 1,050 tiles of 10 × 9 px created by the script; ivory starting state, orange marked state. The three squares already marked carry pxt-on in the HTML: the script reads that state on load. The counter at the bottom belongs to the scene. In the capture, the mouse's two real clicks mark 28 then 63.
Bare roof, roof fitted with panels — a solar installer's simulator — Pixel Transition example 3

③ Bare roof, roof fitted with panels — a solar installer's simulator

WhenA couple wants to know what their south side would yield. They click the roof of the drawn house: midnight blue slabs cover the tiles one by one, then reveal ten neatly aligned panels. Beside it, the power and the estimated output appear. A second click gives the roof back its tiles.
WhyTiles arriving in random order suggest a fitting job, panel after panel: the gesture tells the story of the work, where a fade would only have shown a before and an after.
Settings300 × 156 px .pxt-scene. Each layer has a solid background color (terracotta, midnight blue) and, on top, gradients drawing the roof tiles or the panel frames: the effect's tiles take the solid color. The figures on the right belong to the scene, which watches the surface's class. In the capture, a real mouse click lands on the roof.

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" and tabindex="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-pressed follows the state, and at 600 ms the script swaps aria-hidden between 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.

Chrome 87+✓ Full (measured in Chromium 149)
Firefox 66+✓ Full (measured in Firefox 151)
Safari 14.1+✓ Full (measured in WebKit 26.5)
Edge 87+✓ Full (Chromium engine)
Mobile iOS 14.5+✓ Not checked on a device
Android Chrome 87+✓ Full (emulated touch)

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):

index.html — structure
<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 / propertyDefaultEffect
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

Pixelate Dissolve changes page: a separate button launches 32 large black blocks that swell, hide the screen, then shrink onto the next page. Pixel Transition toggles one object between two states: no separate button, you click the surface; 70 finer tiles, which do not change size; and above all they wear the color of the state to come, so you never cross black. The first to go from one screen to another, the second for a two-state tile, square or picture.
Because the script reads 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.
Write the 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.