Before / AfterPRO
A draggable divider compares the original with the upscaled or enhanced result.
Code
1 file · 254 lines of TypeScriptPRO
Before / After is part of Pro
Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.
Motion notes
- The handle glides to clicks and keyboard steps on a layout spring, then sticks to the pointer once it has caught up, so dragging never feels laggy.
- While nobody touches it, the handle sways a few percent on its own. The sway is a visual offset on top of the real value, so it never changes what's reported.
- With no separate original, the same image is pixelated, softened and desaturated by an inline SVG filter, so one asset is enough for a demo.
- Labels fade as their half gets too thin to hold them. With reduced motion the handle jumps and the idle sway is off.
Usage
Example
<ImageCompare
src={upscaled.url}
beforeSrc={original.url}
beforeLabel="Original"
afterLabel="4× upscale"
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | — | The enhanced image, shown right of the handle. |
| beforeSrc | string | — | A separate original. Leave it out to show `src` degraded. |
| beforeFilter | string | — | CSS filter for the original, replacing the built-in pixelate. |
| alt | string | — | Describes the image for screen readers. |
| beforeLabel | string | "Original" | Label on the left half. |
| afterLabel | string | "Enhanced" | Label on the right half. |
| position | number | — | Controlled handle position, 0–100 from the left. |
| defaultPosition | number | 50 | Starting position when uncontrolled. |
| onPositionChange | (position: number) => void | — | Called while dragging and on arrow keys. |
| hint | boolean | true | Sways the handle while idle, until the first interaction. |
| className | string | — | Size it here; the default is w-64 at 3:4. |
