For Tailwind CSS v3 docs, click here.

左右对比

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

通过 CLI 安装

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

手动安装

在同一个文件中,复制并粘贴以下代码:

Compare.vue
StarField.vue

示例

Drag handle with custom content

AutoPlay

Custom Content with AutoPlay

API

Props

Prop 名称类型默认值描述
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 NamePayload描述
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 Name默认值 Content描述
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.
handle默认值 slider handle with dots iconCustom handle for the slider. Automatically positioned at the dividing line. Should handle positioning with absolute positioning.

感谢