본문 바로가기
Front-end/애니메이션

animation @keyframes 으로 반복되는 움직임 만들기

by mooyou 2025. 5. 15.
728x90
300x250
SMALL

animation효과

  • css @keyframes와 animation 속성을 사용하면 반복되거나 시간 기반으로 동작하는 애니메이션을 만들 수 있다.
  • transition은 상태 변화에 반응하지만, animation은 자동 반복도 가능하다.

주요 속성

  • @keyframes : 애니메이션의 단계 정의
  • animation-name : 사용할 키프레임 이름
  • animation-duration : 애니메이션 시간
  • animation-iteration-count : 반복 횟수
  • animation-delay : 시작 지연
  • animation-fill-mode : 종료 후 상태 유지

 

주요 문법

@keyframes animationName {
  0%   { 속성: 값; }
  50%  { 속성: 값; }
  100% { 속성: 값; }
}

.element {
  animation-name: animationName;
  animation-duration: 2s;           /* 애니메이션 총 시간 */
  animation-timing-function: ease;  /* 속도 곡선 */
  animation-delay: 0s;              /* 시작 전 지연 시간 */
  animation-iteration-count: infinite; /* 반복 횟수 */
  animation-direction: alternate;   /* 반복 방향 */
  animation-fill-mode: forwards;    /* 종료 후 상태 유지 */
}

 


 

예제 1: 로딩 스피너

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <style>
    .spinner {
      width: 40px;
      height: 40px;
      border: 4px solid #ccc;
      border-top-color: #3498db;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
  </style>
</head>
<body>
  <div class="spinner"></div>
</body>
</html>

 

 

 


 

 

예제2 : 버튼 깜빡임

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <style>
    .blinking-btn {
      padding: 10px 20px;
      background-color: #e74c3c;
      color: white;
      border: none;
      animation: blink 1s steps(2, start) infinite;
    }

    @keyframes blink {
      0%, 100% { opacity: 1; }
      50% { opacity: 0; }
    }
  </style>
</head>
<body>
  <button class="blinking-btn">주의!</button>
</body>
</html>

 

 

 

728x90
반응형
LIST

댓글