Compare

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

Examples

Drag handle with custom content

AutoPlay

Custom Content with AutoPlay

API

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
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
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.

Component Code

You can copy and paste the following code to create this component:

Compare.vue
StarField.vue

Credits