Compare

Slide to compare any two pieces of content - images, designs, code, or custom elements

Install using CLI

npm
pnpm
bun
yarn
npx shadcn-vue@latest add "https://inspira-ui.com/r/compare.json"

Install Manually

Copy and paste the following code in the same folder

Compare.vue
StarField.vue

Examples

Drag handle with custom content

AutoPlay

Custom Content with AutoPlay

API

Props

Prop NameTypeDefaultDescription
firstImagestring""URL of the first image
secondImagestring""URL of the second image
firstImageAltstring"First image"Alt text for first image
secondImageAltstring"Second image"Alt text for second image
classstring""Additional classes for the component
firstContentClassstring""Classes applied to first content wrapper
secondContentClassstring""Classes applied to second content wrapper
initialSliderPercentagenumber50Initial position of slider (0-100)
slideMode"hover" | "drag""hover"Interaction mode for the slider
showHandlebarbooleantrueShow/hide the handle bar
autoplaybooleanfalseEnable/disable autoplay
autoplayDurationnumber5000Duration of autoplay cycle in ms

Events

Event NamePayloadDescription
update:percentagenumberEmitted when slider position changes (0-100)
drag:start-Emitted when dragging starts
drag:end-Emitted when dragging ends
hover:enter-Emitted when mouse enters component
hover:leave-Emitted when mouse leaves component

Slots

Slot NameDefault ContentDescription
first-content<img> element if firstImage prop is providedContent shown on the left/first side of the comparison. Has full access to component width/height.
second-content<img> element if secondImage prop is providedContent shown on the right/second side of the comparison. Has full access to component width/height.
handleDefault slider handle with dots iconCustom handle for the slider. Automatically positioned at the dividing line. Should handle positioning with absolute positioning.

Credits