Skip to content
Media Fancy Stable

Compare

.md

Before/after image comparison slider split by a blade of light: a white-hot seam with a chromatic fringe, pulses running along it and a trail that stretches with the speed of the gesture

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { Compare } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { Compare } from "fancy-ui-svelte";
</script>

<div class="flex justify-center">
	<Compare
		firstImage="https://images.unsplash.com/photo-1505765050516-f72dcac9c60e?w=800&q=80"
		secondImage="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=800&q=80"
		firstImageAlt="Forest in autumn"
		secondImageAlt="Mountains at sunrise"
		class="rounded-lg"
	/>
</div>

Examples

Basic Usage

Hover mode comparison.

Drag Mode

Click and drag to control.

Autoplay

Automatic animation.

Custom Content

Use snippets instead of images.

Beam Colors

Tint the seam with your own colours.

Props

PropTypeDefaultDescription
firstImage string""URL of the first (left) image
secondImage string""URL of the second (right) image
firstImageAlt string"First image"Alt text for the first image
secondImageAlt string"Second image"Alt text for the second image
firstContentClass string""CSS classes for the first content container
secondContentClass string""CSS classes for the second content container
initialSliderPercentage number50Initial slider position (0-100)
slideMode "hover" | "drag""hover"How the slider is controlled
showHandlebar booleantrueShow the drag handle bar
autoplay booleanfalseAutomatically animate the slider back and forth
autoplayDuration number5000Duration of one autoplay cycle in ms
beamColors string[]["#22d3ee", "#818cf8", "#f472b6"]Beam colours: left fringe, centre, right fringe (one or more colours)
label string"Comparison slider"Accessible name of the slider
class string""Additional CSS classes for the root element
onpercentagechange (percentage: number) => void-Called with the slider position (0-100) whenever it changes
ondragstart () => void-Called when a drag on the slider begins
ondragend () => void-Called when the drag ends
onhoverenter () => void-Called when the pointer enters the comparison area
onhoverleave () => void-Called when the pointer leaves the comparison area

Slots

SlotDescription
firstContent Custom content to render in the first (left) panel instead of an image
secondContent Custom content to render in the second (right) panel instead of an image
handle Custom drag handle element