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

Animated Image

원문 보기 위키 갱신

Shoelace의 Animated Image 컴포넌트(sl-animated-image)는 애니메이션 GIF와 WEBP를 표시하고, 사용자가 상호작용하면 재생/정지를 할 수 있게 해주는 컴포넌트예요. 마우스를 올리면 재생되고 벗어나면 멈추는 방식으로 동작한답니다.

출처: 문서

본문

애니메이션 GIF와 WEBP를 표시하고, 상호작용에 따라 재생과 정지를 하는 컴포넌트예요.

<sl-animated-image
  src="https://shoelace.style/assets/images/walk.gif"
  alt="Animation of untied shoes walking on pavement"
></sl-animated-image>
import SlAnimatedImage from '@shoelace-style/shoelace/dist/react/animated-image';
const App = () => (
  <SlAnimatedImage
    src="https://shoelace.style/assets/images/walk.gif"
    alt="Animation of untied shoes walking on pavement"
  />
);

이 컴포넌트는 정지 프레임(freeze frame)을 그리기 위해 <canvas>를 사용하기 때문에, 이미지는 크로스 오리진(cross-origin) 제약의 영향을 받아요.

Examples

WEBP Images

GIF와 WEBP 이미지 모두 지원해요.

<sl-animated-image
  src="https://shoelace.style/assets/images/tie.webp"
  alt="Animation of a shoe being tied"
></sl-animated-image>
import SlAnimatedImage from '@shoelace-style/shoelace/dist/react/animated-image';
const App = () => (
  <SlAnimatedImage src="https://shoelace.style/assets/images/tie.webp" alt="Animation of a shoe being tied" />
);

Setting a Width and Height

사용자 지정 크기를 설정하려면 호스트 요소(host element)에 width나 height를 적용하면 돼요.

<sl-animated-image
  src="https://shoelace.style/assets/images/walk.gif"
  alt="Animation of untied shoes walking on pavement"
  style="width: 150px; height: 200px;"
>
</sl-animated-image>
import SlAnimatedImage from '@shoelace-style/shoelace/dist/react/animated-image';
const App = () => (
  <SlAnimatedImage
    src="https://shoelace.style/assets/images/walk.gif"
    alt="Animation of untied shoes walking on pavement"
    style={{ width: '150px', height: '200px' }}
  />
);

Customizing the Control Box

스타일에서 control-box 파트(part)를 대상으로 지정하면 컨트롤 박스의 모양과 위치를 바꿀 수 있어요.

<sl-animated-image
  src="https://shoelace.style/assets/images/walk.gif"
  alt="Animation of untied shoes walking on pavement"
  class="animated-image-custom-control-box"
></sl-animated-image>
<style>
  .animated-image-custom-control-box::part(control-box) {
    top: auto;
    right: auto;
    bottom: 1rem;
    left: 1rem;
    background-color: deeppink;
    border: none;
    color: pink;
  }
</style>
import SlAnimatedImage from '@shoelace-style/shoelace/dist/react/animated-image';
const css = `
  .animated-image-custom-control-box::part(control-box) {
    top: auto;
    right: auto;
    bottom: 1rem;
    left: 1rem;
    background-color: deeppink;
    border: none;
    color: pink;
  }
`;
const App = () => (
  <>
    <SlAnimatedImage
      className="animated-image-custom-control-box"
      src="https://shoelace.style/assets/images/walk.gif"
      alt="Animation of untied shoes walking on pavement"
    />
    <style>{css}</style>
  </>
);

Importing

autoloader나 전통적인 loader를 사용하고 있다면 이 부분은 무시해도 돼요. 그 외의 경우 아래 스니펫 중 하나를 골라 이 컴포넌트만 골라(cherry pick) 가져올 수 있답니다.

Script / Import / Bundler / React

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

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

CDN에서 JavaScript import로 이 컴포넌트를 가져오려면:

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

bundler를 사용해 이 컴포넌트를 가져오려면:

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

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

import SlAnimatedImage from '@shoelace-style/shoelace/dist/react/animated-image';

Slots

Name Description
play-icon Optional play icon to use instead of the default. Works best with sl-icon.
pause-icon Optional pause icon to use instead of the default. Works best with sl-icon.

슬롯(slots) 사용에 대해 더 알아보기.

Properties

Name Description Reflects Type Default
src The path to the image to load. string -
alt A description of the image used by assistive devices. string -
play Plays the animation. When this attribute is remove, the animation will pause. boolean -
updateComplete A read-only promise that resolves when the component has finished updating.

속성과 프로퍼티(attributes and properties)에 대해 더 알아보기.

Events

Name React Event Description Event Detail
sl-load onSlLoad Emitted when the image loads successfully. -
sl-error onSlError Emitted when the image fails to load. -

이벤트(events)에 대해 더 알아보기.

Custom Properties

Name Description Default
--control-box-size The size of the icon box.
--icon-size The size of the play/pause icons.

CSS 커스텀 프로퍼티(custom properties) 커스터마이징에 대해 더 알아보기.

Parts

Name Description
control-box The container that surrounds the pause/play icons and provides their background.

CSS 파트(parts) 커스터마이징에 대해 더 알아보기.

Dependencies

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

  • sl-icon

더 알아보기 (Learn more)