본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Vue ImageCompare 컴포넌트

원문 보기 위키 갱신

ImageCompare는 슬라이더로 두 이미지를 나란히 비교하는 컴포넌트예요. 전후 비교(before/after) 콘텐츠를 직관적으로 보여 주는 데 딱이에요.

출처: 문서

본문

Vue ImageCompare Component

Compare two images side by side with a slider.

Import

import ImageCompare from 'primevue/imagecompare';

Accessibility

Screen Reader ImageComponent 컴포넌트는 내부적으로 네이티브 range 슬라이더를 사용해요. 컴포넌트를 설명하는 값은 aria-labelledby와 aria-label 프로퍼티로 정의할 수 있어요. Keyboard Support Key Function tab 컴포넌트로 포커스를 이동해요. left arrow up arrow 값을 감소시켜요. right arrow down arrow 값을 증가시켜요. home 최솟값으로 설정해요. end 최댓값으로 설정해요. page up 값을 10 단계 증가시켜요. page down 값을 10 단계 감소시켜요.

<span id="image_label">Compare Images</span>
<ImageCompare class="shadow-lg rounded-2xl" aria-labelledby="image-label">
    ...
</ImageCompare>

<ImageCompare class="shadow-lg rounded-2xl" aria-label="Compare Images">
    ...
</ImageCompare>

Basic

이미지는 left와 right 슬롯을 사용한 템플릿으로 정의해요. 컨테이너의 크기는 style이나 class 프로퍼티로 지정하세요.

<ImageCompare class="shadow-lg rounded-2xl">
    <template #left>
        <img src="~/assets/images/island1.jpg" />
    </template>
    <template #right>
        <img src="~/assets/images/island2.jpg" />
    </template>
</ImageCompare>

Responsive

화면 크기별 표시를 최적화하려면 컨테이너 요소에 반응형 스타일을 적용하세요.

<ImageCompare class="sm:!w-96 shadow-lg rounded-2xl">
    <template #left>
        <img src="~/assets/images/island1.jpg" />
    </template>
    <template #right>
        <img src="~/assets/images/island2.jpg" />
    </template>
</ImageCompare>
Composition API Example
<template>
    <div class="card flex justify-center">
        <ImageCompare class="sm:!w-96 shadow-lg">
            <template #left>
                <img src="https://primefaces.org/cdn/primevue/images/compare/island1.jpg" />
            </template>
            <template #right>
                <img src="https://primefaces.org/cdn/primevue/images/compare/island2.jpg" />
            </template>
        </ImageCompare>
    </div>
</template>

Image Compare

Props

Name Type Default Description
tabindex number 0 Index of the element in tabbing order.
ariaLabel string - Defines a string value that labels an interactive element.
ariaLabelledby string - Identifier of the underlying input element.
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough - Used to pass attributes to DOM elements inside the component.
ptOptions any - Used to configure passthrough(pt) options of the component.
unstyled boolean false When enabled, it removes component related styles in the core.

Pass Through Options

Name Type Description
root ImageComparePassThroughOptionType Used to pass attributes to the root's DOM element.
slider ImageComparePassThroughOptionType Used to pass attributes to the slider's DOM element.
hooks any Used to manage all lifecycle hooks.

Theming

CSS Classes

Class Description
p-imagecompare Class name of the root element
p-imagecompare-slider Class name of the slider element

Design Tokens

Token CSS Variable Description
imagecompare.handle.size --p-imagecompare-handle-size Size of handle
imagecompare.handle.hover.size --p-imagecompare-handle-hover-size Hover size of handle
imagecompare.handle.background --p-imagecompare-handle-background Background of handle
imagecompare.handle.hover.background --p-imagecompare-handle-hover-background Hover background of handle
imagecompare.handle.border.color --p-imagecompare-handle-border-color Border color of handle
imagecompare.handle.hover.border.color --p-imagecompare-handle-hover-border-color Hover border color of handle
imagecompare.handle.border.width --p-imagecompare-handle-border-width Border width of handle
imagecompare.handle.border.radius --p-imagecompare-handle-border-radius Border radius of handle
imagecompare.handle.transition.duration --p-imagecompare-handle-transition-duration Transition duration of handle
imagecompare.handle.focus.ring.width --p-imagecompare-handle-focus-ring-width Focus ring width of handle
imagecompare.handle.focus.ring.style --p-imagecompare-handle-focus-ring-style Focus ring style of handle
imagecompare.handle.focus.ring.color --p-imagecompare-handle-focus-ring-color Focus ring color of handle
imagecompare.handle.focus.ring.offset --p-imagecompare-handle-focus-ring-offset Focus ring offset of handle
imagecompare.handle.focus.ring.shadow --p-imagecompare-handle-focus-ring-shadow Focus ring shadow of handle

더 알아보기 (Learn more)