Dissolve
A noise-based reveal between two images, with a thin line of light along the front.
Overview
Dissolve turns one image into another through a noise pattern. The second image appears in islands that grow and merge, with a thin line of light riding the boundary. Both images are cropped to fill the container, like object-fit: cover.
Use it for before and after comparisons, a product shown in two finishes, or a slide change in a gallery. Pick the start with direction: everywhere at once, from one side, or from the center.
Installation
Usage
Set show to the side you want on screen. Changing it plays the dissolve over duration milliseconds; changing it again partway reverses from where it is.
"use client"
import { useState } from "react"
import { Dissolve } from "honestui/shaders"
export function BeforeAfter() {
const [show, setShow] = useState<"from" | "to">("from")
return (
<div className="grid gap-3">
<div className="h-80 overflow-hidden rounded-xl">
<Dissolve
className="size-full"
from="/kitchen-before.jpg"
fromAlt="The kitchen before the renovation, with dark oak cabinets."
to="/kitchen-after.jpg"
toAlt="The kitchen after the renovation, with white cabinets and brass handles."
show={show}
/>
</div>
<button onClick={() => setShow(show === "from" ? "to" : "from")}>
{show === "from" ? "Show after" : "Show before"}
</button>
</div>
)
}Driving progress yourself
Pass progress from 0 to 1 to place the dissolve exactly, for example from a slider or the scroll position. While progress is set, show and duration are ignored.
<Dissolve
className="size-full"
from="/day.jpg"
fromAlt="The harbor at midday."
to="/night.jpg"
toAlt="The harbor at night, lit by the boats."
progress={scrollProgress}
direction="left"
/>Images must be served with CORS headers that allow cross-origin use, because WebGL reads their pixels. Images on your own domain work without extra setup.
Accessibility
The images are real <img> elements with your alt text. Only the image that is mostly on screen is exposed to assistive technology, so its description changes halfway through the dissolve. Pass an empty string for an image that is purely decorative.
The control that changes show is yours to render. Give it a label that names what it shows next, and keep it outside the canvas.
When the user prefers reduced motion, changing show switches images at once instead of dissolving. progress is always followed exactly, since you control it. Until both images have loaded, and without WebGL2, the images crossfade instead.