Notice
Recent Posts
Recent Comments
Link
Β«   2026/05   Β»
일 μ›” ν™” 수 λͺ© 금 ν† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

η„‘μ œ

CSS의 Animation과 @keyframes 본문

<style>

CSS의 Animation과 @keyframes

yo-u-loo 2026. 3. 27. 14:54

 

🟒 animation

μš”μ†Œμ˜ μŠ€νƒ€μΌμ„ μ‹œκ°„μ— 따라 λ‹€μ–‘ν•œ 효과 및 λ³€ν™”μ‹œν‚€λŠ” κΈ°λŠ₯.

 

β—Ό @keyframes (μ• λ‹ˆλ©”μ΄μ…˜μ˜ 섀계도)

μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œκ°„μ˜ 흐름에 λ”°λ₯Έ μŠ€νƒ€μΌ λ³€ν™” 단계λ₯Ό μ •μ˜.

@keyframes μ• λ‹ˆλ©”μ΄μ…˜μ΄λ¦„ {
  from { /* μƒνƒœ */ }
  to { /* μƒνƒœ */ }
}
@keyframes μ• λ‹ˆλ©”μ΄μ…˜μ΄λ¦„ {
  0% { /* μ‹œμž‘ μƒνƒœ */ }
  50% { /* 쀑간 μƒνƒœ */ }
  100% { /* 끝 μƒνƒœ */ }
}
  • from (μ‹œμž‘) 0%, to (끝) 100%.
  • 쀑간 단계(예: 25%, 50%, 75%) μ •μ˜ κ°€λŠ₯.

 

 

🎯 μ£Όμš” 속성 🎯

πŸ”Ή animation-name: 이름.

  • @keyframesμ—μ„œ μ •μ˜ν•œ 이름.

 

πŸ”Ή animation-duration: μ™„λ£Œλ˜λŠ”λ° κ±Έλ¦¬λŠ” μ‹œκ°„.

  • 예: 2s, 500ms.

 

πŸ”Ή animation-timing-function: 속도 λ³€ν™” 방식.

  • 예: linear, ease, ease-in-out

 

πŸ”Ή animation-delay: μ‹œμž‘ μ „ λŒ€κΈ° μ‹œκ°„.

  • 예: 2s, 500ms.

 

πŸ”Ή animation-iteration-count: 반볡 횟수 μ§€μ •.

  • 숫자 λ˜λŠ” infinite(λ¬΄ν•œ)

 

πŸ”Ή animation-direction: μ§„ν–‰ λ°©ν–₯ μ§€μ •.

  • normal: μ •λ°©ν–₯.
  • reverse: μ—­λ°©ν–₯.
  • alternate: μ •λ°©ν–₯ → μ—­λ°©ν–₯ 반볡.

 

πŸ”Ή animation-fill-mode: μ• λ‹ˆλ©”μ΄μ…˜ ν›„ μƒνƒœ.

  • forwards: 끝 μƒνƒœ μœ μ§€.
  • backwards: μ‹œμž‘ μƒνƒœ μœ μ§€.
  • both: λ‘˜ λ‹€ μœ μ§€.

 

 

🧿 μ€‘μš” ν•¨μˆ˜ 및 μ œμ–΄ 속성 🧿

πŸ”Ή animation-fill-mode:μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ‹œμž‘λ˜κΈ° μ „κ³Ό λλ‚œ 후에 μš”μ†Œμ— μ–΄λ–€ μŠ€νƒ€μΌμ„ μ μš©ν• μ§€λ₯Ό κ²°μ •.

  • none: μ• λ‹ˆλ©”μ΄μ…˜ μ™Έμ—λŠ” μŠ€νƒ€μΌμ„ μœ μ§€ν•˜μ§€ μ•ŠμŒ. (κΈ°λ³Έκ°’)
  • forwards: μ• λ‹ˆλ©”μ΄μ…˜ μ’…λ£Œ ν›„ λ§ˆμ§€λ§‰ μƒνƒœλ₯Ό μœ μ§€.
  • backwards: μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μ „ 처음 μƒνƒœλ₯Ό μœ μ§€.
  • both: μ‹œμž‘ μ „κ³Ό μ’…λ£Œ ν›„ λͺ¨λ‘ μƒνƒœλ₯Ό μœ μ§€ (forwards + backwards).

 

πŸ”Ή animation-play-state: μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ‹€ν–‰ 쀑인지 μΌμ‹œμ •μ§€ μƒνƒœμΈμ§€λ₯Ό κ²°μ •.

  • running: μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ •μƒμ μœΌλ‘œ 싀행됨. (κΈ°λ³Έκ°’)
  • paused: μ• λ‹ˆλ©”μ΄μ…˜μ΄ μΌμ‹œμ •μ§€λ¨. (ν•„μš”ν•˜λ©΄ JSλ‚˜ CSS둜 λ‹€μ‹œ μ‹€ν–‰ κ°€λŠ₯)

 

 

πŸ”¨ μΆ•μ•½ν˜• 속성 (Shorthand)

animation 속성을 ν•œ μ€„λ‘œ μ •μ˜ν•˜λŠ” 속성.

.box {
animation: [name] [duration] [timing-function] [delay] [iteration-count] [direction] [fill-mode];
}
  • 문법: animation: 이름 μ§€μ†μ‹œκ°„ 타이밍 λŒ€κΈ°μ‹œκ°„ 횟수 λ°©ν–₯ μŠ€νƒ€μΌμš”μ†Œ;
    • μ‹œκ°„ κ΄€λ ¨ κ°’ μˆœμ„œ μœ„μΉ˜ 주의, 이름&μ§€μ†μ‹œκ°„μ€ ν•„μˆ˜ κ°’, μƒλž΅ μ‹œ κΈ°λ³Έκ°’ 적용. 

 

 

πŸ“β€Š POINT πŸ“

βœ”οΈ @keyframes λŠ” μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œλ‚˜λ¦¬μ˜€, animation 속성은 이λ₯Ό μ‹€ν–‰ν•˜λŠ” μ„€μ •. βœ”οΈ

βœ”οΈ infinite λ₯Ό ν™œμš©ν•˜λ©΄ λ‘œλ”© λ°”μ²˜λŸΌ 계속 λŒμ•„κ°€λŠ” 효과λ₯Ό μ‰½κ²Œ λ§Œλ“ λ‹€. βœ”οΈ

βœ”οΈ alternate λ°©ν–₯ 섀정은 왕볡 μ• λ‹ˆλ©”μ΄μ…˜μ„ λ§Œλ“€ λ•Œ keyframesλ₯Ό 절반만 써도 되게 ν•΄μ€€λ‹€. βœ”οΈ

 

 

πŸ“‹ 속성별 예제 λͺ¨μŒ πŸ“‹

속성 μ½”λ“œ μ˜ˆμ‹œ μ„€λͺ…
Iteration animation-iteration-count: 3; λ”± 3번만 움직이고 정지함
Direction animation-direction: alternate; κ°”λ‹€κ°€ λ‹€μ‹œ λŒμ•„μ˜€λŠ” 왕볡 μš΄λ™
Fill-mode animation-fill-mode: forwards; μ• λ‹ˆλ©”μ΄μ…˜ μ’…λ£Œ ν›„ λ§ˆμ§€λ§‰ λͺ¨μŠ΅ μœ μ§€
Play-state .box:active { animation-play-state: paused; } ν΄λ¦­ν•˜λŠ” λ™μ•ˆ μ›€μ§μž„μ΄ 멈좀

 


 

βš™οΈ μ‹€μ „ 예제 μ½”λ“œ: 톡톡 νŠ€λŠ” 곡 βš™οΈ

/* 1. μ• λ‹ˆλ©”μ΄μ…˜ 섀계도 λ§Œλ“€κΈ° */
@keyframes bounce {
  0% { transform: translateY(0); }
  50% { transform: translateY(-50px); }
  100% { transform: translateY(0); }
}

.ball {
  width: 50px;
  height: 50px;
  background-color: #3498db;
  border-radius: 50%;
  
  /* 2. μ• λ‹ˆλ©”μ΄μ…˜ μ μš©ν•˜κΈ° */
  /* 이름(bounce), 0.6μ΄ˆκ°„, λΆ€λ“œλŸ½κ²Œ(ease-in-out), λ¬΄ν•œλ°˜λ³΅(infinite) */
  animation: bounce 0.6s ease-in-out infinite;
}

 

'<style>' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

perspective  (0) 2026.03.27
transition 속성  (1) 2026.03.27
Functions의 filter속성과 ν•¨μˆ˜  (0) 2026.03.27
transform 속성과 functions (ν•¨μˆ˜)  (0) 2026.03.26
Pseudo-elements (μ˜μ‚¬ μš”μ†Œ)  (0) 2026.03.26