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

이미지 컴페어러 (Image Comparer)

원문 보기 위키 갱신

슬라이딩 패널로 비슷한 사진들 사이의 시각적 차이를 비교하는 컴포넌트예요. 이미지 편집 전·후 비교나 A/B 비교에 아주 유용해요. _ | SlImageComparer, Shoelace 2.0부터 제공되고 있으며 stable 상태예요.

최상의 결과를 얻으려면 같은 크기의 이미지를 쓰는 게 좋아요. 슬라이더는 드래그하거나 왼쪽·오른쪽 화살표 키로 조절할 수 있어요. (팁: shift + 화살표 키를 누르면 슬라이더가 더 크게 움직이고, home + end로 처음이나 끝으로 이동할 수 있어요.)

출처: 문서

본문

| SlImageComparer — Since 2.0, stable

슬라이딩 패널로 비슷한 사진 사이의 시각적 차이를 비교할 수 있어요.

최상의 결과를 얻으려면 같은 크기의 이미지를 사용하는 게 좋아요. 슬라이더는 드래그하거나 왼쪽·오른쪽 화살표 키로 조절할 수 있어요. (팁: shift + arrows를 누르면 슬라이더가 더 큰 간격으로 움직이고, home + end로 처음이나 끝으로 이동할 수 있어요.)

<sl-image-comparer>
  <img
    slot="before"
    src="https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=800&q=80&sat=-100&bri=-5"
    alt="Grayscale version of kittens in a basket looking around."
  />
  <img
    slot="after"
    src="https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=800&q=80"
    alt="Color version of kittens in a basket looking around."
  />
</sl-image-comparer>
import SlImageComparer from '@shoelace-style/shoelace/dist/react/image-comparer';
const App = () => (
  <SlImageComparer>
    <img
      slot="before"
      src="https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=800&q=80&sat=-100&bri=-5"
      alt="Grayscale version of kittens in a basket looking around."
    />
    <img
      slot="after"
      src="https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=800&q=80"
      alt="Color version of kittens in a basket looking around."
    />
  </SlImageComparer>
);

Examples

Initial Position

position 속성으로 슬라이더의 초기 위치를 설정할 수 있어요. 0에서 100 사이의 백분율 값이에요.

<sl-image-comparer position="25">
  <img
    slot="before"
    src="https://images.unsplash.com/photo-1520903074185-8eca362b3dce?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=1200&q=80"
    alt="A person sitting on bricks wearing untied boots."
  />
  <img
    slot="after"
    src="https://images.unsplash.com/photo-1520640023173-50a135e35804?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=2250&q=80"
    alt="A person sitting on a yellow curb tying shoelaces on a boot."
  />
</sl-image-comparer>
import SlImageComparer from '@shoelace-style/shoelace/dist/react/image-comparer';
const App = () => (
  <SlImageComparer position={25}>
    <img
      slot="before"
      src="https://images.unsplash.com/photo-1520903074185-8eca362b3dce?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=1200&q=80"
      alt="A person sitting on bricks wearing untied boots."
    />
    <img
      slot="after"
      src="https://images.unsplash.com/photo-1520640023173-50a135e35804?ixlib=rb-1.2.1&ixid=eyJhcH...MDd9&auto=format&fit=crop&w=2250&q=80"
      alt="A person sitting on a yellow curb tying shoelaces on a boot."
    />
  </SlImageComparer>
);

Importing

autoloader나 전통적인 loader를 사용하고 있다면 이 부분은 건너뛰어도 돼요. 그 외에는 아래 스니펫 중 원하는 걸 골라 이 컴포넌트만 골라 가져올 수 있어요.

Script / Import / Bundler / React 방식이 준비되어 있어요.

CDN에서 <script> 태그로 이 컴포넌트를 가져오려면:

<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/image-comparer/image-comparer.js"></script>

CDN에서 JavaScript import로 가져오려면:

import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/image-comparer/image-comparer.js';

Bundler를 사용해 가져오려면:

import '@shoelace-style/shoelace/dist/components/image-comparer/image-comparer.js';

React 컴포넌트로 가져오려면:

import SlImageComparer from '@shoelace-style/shoelace/dist/react/image-comparer';

Slots

Name Description
before The before image, an or element.
after The after image, an or element.
handle The icon used inside the handle.

슬롯 사용법에 대해 더 알아보세요.

Properties

Name Description Reflects Type Default
position The position of the divider as a percentage. number 50
updateComplete A read-only promise that resolves when the component has
finished updating.

속성과 프로퍼티에 대해 더 알아보세요.

Events

Name React Event Description Event Detail
sl-change onSlChange Emitted when the position changes. -

이벤트에 대해 더 알아보세요.

Custom Properties

Name Description Default
--divider-width The width of the dividing line.
--handle-size The size of the compare handle.

CSS 커스텀 프로퍼티 커스터마이징에 대해 더 알아보세요.

Parts

Name Description
base The component’s base wrapper.
before The container that wraps the before image.
after The container that wraps the after image.
divider The divider that separates the images.
handle The handle that the user drags to expose the after image.

CSS 파트 커스터마이징에 대해 더 알아보세요.

Dependencies

이 컴포넌트는 다음 의존성들을 자동으로 가져와요.

  • ``

더 알아보기 (Learn more)