로고로고

Lottie 애니메이션 사용 방법

2025년 3월 7일

1. Lottie 애니메이션 JSON 파일 준비

2. 라이브러리 설치

npm install lottie-react
yarn add lottie-react

3. Lottie 애니메이션 사용 예시

import React from 'react';
import Lottie from 'lottie-react';
import animationData from '../public/animations/your-animation.json';// JSON 파일 경로export default function LottieAnimationExample() {
  return (
    <div style={{ width: 300, height: 300 }}>
      <Lottie animationData={animationData} loop={true} autoplay={true} />
    </div>
  );
}

4. 추가 설정 및 제어

import React, { useRef } from 'react';
import Lottie from 'lottie-react';
import animationData from '../public/animations/your-animation.json';

export default function LottieControlled() {
  const lottieRef = useRef(null);

  const handlePlay = () => {
    lottieRef.current.play();
  };

  const handlePause = () => {
    lottieRef.current.pause();
  };

  return (
    <div>
      <Lottie ref={lottieRef} animationData={animationData} loop={true} autoplay={false} />
      <button onClick={handlePlay}>Play</button>
      <button onClick={handlePause}>Pause</button>
    </div>
  );
}

5. 주의 사항