Skip to the content

Pixel swap

The cursor opens a trail of pixels onto a second image, and each square closes again on its own a moment later.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

  3. Add custom JS

  4. Use it on your own elements

    Custom attribute
    Select the element on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-pixel-swap Marks the element the effect plays on. It takes no value: leave the value field empty.
    Settings
    Every setting is a custom attribute too, added the same way and on the same element. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-accent #ffab1a Flash colour on a square that has just turned. Options: any CSS colour; taken out of this block, --pixel-swap-accent on the box then the page's --accent take over.
    data-cell 15 Side of one square the trail turns over, kept in px so the grain is the same on every screen.
    data-radius 74 Half width of the brush that opens the second image, any CSS unit.
    data-edge 0.42 How ragged the rim of that brush is, 0 to 1.
    data-hold 0.9 How long a square keeps showing the second image once the cursor has left it, in seconds.
    data-hold-jitter 0.55 Spread of that hold from one square to the next, 0 to 1.
    data-front 0.3 How long a square that has just turned keeps its accent flash, in seconds.
    data-front-intensity 0 Strength of that flash, 0 to 1.
    data-flat 1 How solid the lit squares are, 0 to 1.

What it does

Pixel swap is a cursor animation for Webflow and vanilla JavaScript, with no library. Also called pixel image swap on hover, image change on hover or pixelate image on hover.

The cursor opens a trail of pixels onto a second image, and each square closes again on its own a moment later. Nothing has to be uncovered: you see what is underneath where you pass, and the picture comes back behind you. Squares open straight onto the second image and close one by one, so the trail dissolves in pixels; an accent flash on the squares that open is a setting, off by default. The effect works on one image box and fills it edge to edge, so a product shot shows its second colourway, a landscape shows the same view after dark, a poster shows its other side. In the reference demo the three boxes hold two photographs each, a small vase and a single stem and then its other colourway, and the squares never look at what they are showing, so any pair of pictures goes through the same code. Each box keeps two off-screen sources and one visible canvas, one bit per square, and only the squares that changed are ever redrawn.

Updated

Questions

Paste the component, then replace the two Image elements inside each box in the Navigator: the first is the picture shown, the second is the one the cursor opens onto. The settings are custom attributes on the box that carries data-pixel-swap, for instance data-hold="0.8". The size and ratio of the box come from its class, like any other element.

No. It uses no library at all. Each box keeps two off-screen sources and one visible canvas, and only the squares that changed are redrawn.

Set data-hold on the box, in seconds. The default is 0.9. A lower value closes the trail right behind the cursor, a higher one keeps the second image open across the whole box.

No, the sizes do not have to match: every source is redrawn once to the size of the box, centred and cropped like object-fit: cover. The framing does have to match, because squares are swapped at the same coordinates and a different crop reads as a glitch.

A tap turns the whole box over to the second image, and a second tap brings the first one back. The same full swap replaces the trail under prefers-reduced-motion: hovering turns the whole box over and leaving brings it back.