Index
Index0. File download1. Keyframe1.1 Keyframeμ λνμ¬1.2. Keyframe κ·μΉ1.3 Animation μ μ©νκΈ°1.3.1 animationμ λ¨μΌ μμ±λ€2. μ€νν΄ λ³΄λ©° λ°°μ°λ Keyframe μμ 2.1 λΉλ© μ¬λ¦¬κΈ°2.2 λΉλ© 2κ° μ¬λ¦¬κΈ°2.3 λΉλ© 3κ°μ λ₯μ΄μ§μ¬λ λ°°μΉ2.4 λΉλ© 3κ°μ λ₯μ΄μ§μ¬λ κ±·κ²νκΈ°2.5 μ¬λ¬λΆμ μν κ³Όμ
0. File download
1. Keyframe
1.1 Keyframeμ λνμ¬
@keyframes
μ λνμ¬ κ°λ²Όμ΄ μμ λ₯Ό λ³΄κ³ κ°λλ‘ νκ² μ΅λλ€.<!DOCTYPE html> <html> <head> <style> /* ν€νλ μ μ΄λ¦ == μ λλ©μ΄μ μ΄λ¦ */ @keyframes hojun { 0% { transform: translate(0, 0); } 100% { transform: translate(300px, 0) rotate(360deg) scale(2); } } div { margin: 200px; width: 100px; height: 100px; background-color: red; animation: hojun 1s; } </style> </head> <body> <div>hello world</div> </body> </html>
ν΄λΉ
@keyframes
hojunμ μ€μ νμ¬ divμ animationμΌλ‘ 1μ΄κ°κ²©μΌλ‘ μ£Όλ©΄ μλμ κ°μ΄ μ€νλκ² λ©λλ€.
μ΄μ²λΌ Keyframeμ μ΄λ€ λ³νκ° μΌμ΄λλ μ§μ μ μ€μ νμ¬ νΉμ μκ° λμ ν΄λΉ Propertyμ Valueλ₯Ό λ³νμν΅λλ€.
+ transitionκ³Ό animationμ μ°¨μ΄μ
transitionκ³Ό animation μμ±μ Javascriptμ λμ μμ΄ μ€λΈμ νΈμ μ§μ μ λλ©μ΄μ
ν¨κ³Όλ₯Ό μ μ©ν λ μ¬μ©ν©λλ€. transitionκ³Ό animationμ
μμ μνμ λν μμ‘΄ μ¬λΆ
μ λν΄ μ°¨μ΄λ₯Ό κ°μ§λλ€. transitionμ μμμ μνκ° λ³κ²½λμ΄μΌ μ λλ©μ΄μ
μ μ€νν μ μμ§λ§, animation μμ±μ μμμ μν λ³νμ κ΄κ³μμ΄ μ λλ©μ΄μ
μ μ€νν μ μμ΅λλ€. λν animation μμ±μ @keyframes
μμ±μ μ΄μ©ν΄ νλ μμ μΆκ°ν μ μμ΅λλ€.1.2. Keyframe κ·μΉ
@keyframes
μ μ λλ©μ΄μ
μ΄ λ§λ€μ΄μ§λ λΆλΆμ
λλ€. from
μμ±μ΄λ 0%
μμ±μ μ€μ ν μ€νμΌλΆν° to
μμ±μ΄λ 100%
μμ±μ μ€μ ν μ€νμΌλ‘ μ μ°¨ λ³κ²½λλ©΄μ μ λλ©μ΄μ
μ΄ μ¬μλ©λλ€. 0%κ³Ό 100% μ¬μ΄μλ μ¬λ¬ κ°μ μ€κ° μμ±μ μ€μ ν μ μμ΅λλ€./* [ from ~ to μμ± ] */ @keyframes animation-name { /* μ λλ©μ΄μ μ μμ νλ μ */ from { styles; } /* μ λλ©μ΄μ μ μ’ λ£ νλ μ */ to { styles; } /* [ 0% ~ 100% μμ± ] */ @keyframes animation-name { /* μ λλ©μ΄μ μ μμ νλ μ */ 0% { styles; } 50% { styles; } /* μ λλ©μ΄μ μ μ’ λ£ νλ μ */ 100% { styles; }
1.3 Animation μ μ©νκΈ°
CSS3 μ λλ©μ΄μ
μ μ΄μ©νλ©΄ μ¬λ¬ κ°μ CSS μ€νμΌμ λΆλλ½κ² μ νμν¬ μ μμ΅λλ€.
@keyframes
μ CSS μ€νμΌμ λ³ν κ³Όμ μ λνλΌ λ μ¬μ©λ©λλ€. @keyframes
μ μ΄μ©ν μ λλ©μ΄μ
μ @transition
λ³΄λ€ μ λ°ν ν¨κ³Όλ₯Ό ꡬνν μ μμ΅λλ€.1.3.1 animationμ λ¨μΌ μμ±λ€
- animation-name
μ λλ©μ΄μ
μ μ¬μ(νΈμΆ) νκΈ° μν΄μλ λ°λμ μ΄λ¦μ μ μν΄μΌ ν©λλ€. nameμ
@keyframes
μμ±μμ μ€μ ν μ΄λ¦μ λμΌνκ² μ¬μ©ν©λλ€.
/* ν€νλ μ μ΄λ¦ == μ λλ©μ΄μ μ΄λ¦ */ @keyframes yoon { 0% { styles; } 100% { styles; } } div{ /* μ λλ©μ΄μ μ΄λ¦ */ animation-name: yoon; }
+ animation-name μ΄λ¦ κ·μΉ
animation-nameμ μμμλ
μλ¬Έ μλ¬Έμ, μ«μ, λ¬Έμμ΄, μΈλλ°(_), νμ΄ν(-)
μ μ¬μ©ν©λλ€. μλ¬Έ λλ¬Έμ, μ«μ, νΉμλ¬Έμλ μ¬μ©ν μ μμ΅λλ€(νμΌ λ° ν΄λλͺ
μλ νμ©). μ¬λ¬ κ°μ animation-nameμ λμμ λμ΄ν κ²½μ° ,
λ₯Ό μ¬μ©ν©λλ€./* [ μ¬λ°λ₯Έ μ΄λ¦ μμ ] */ animation-name: yoon; /* μλ¬Έ μλ¬Έμλ‘ μμνλ μ΄λ¦ */ animtaion-name: _yoon; /* μΈλλ°(_)λ‘ μμνλ μ΄λ¦ */ animation-name: -yoon; /* νμ΄ν(-)μΌλ‘ μμνλ μ΄λ¦ */ animation-name: yoon1, yoon2; /* μ¬λ¬ κ°μ animation-name λμ΄ */ /* [ μλͺ»λ μ΄λ¦ μμ ] */ animation-name: Name-yoon; /* μλ¬Έ λλ¬Έμλ‘ μμνλ μ΄λ¦ */ animation-name: *-name-yoon; /* νΉμλ¬Έμλ‘ μμνλ μ΄λ¦ */ animation-name: 1yoon; /* μ«μλ‘ μμνλ μ΄λ¦ */
- animation-duration
duration μμ±μ μ λλ©μ΄μ
μ μμλΆν° μ’
λ£κΉμ§μ μ΄ μ§μ μκ°μ μ€μ ν λ μ¬μ©νλ©°, transition-durationκ³Ό μ μ¬ν κΈ°λ₯μ μ 곡ν©λλ€. duration κ°μ
μμ
λ‘ μ§μ ν΄μΌ κ·Έ κ²°κ³Όλ₯Ό νμΈν μ μμ΅λλ€. μμ± κ°μ 0 νΉμ μμλ‘ μ€μ νμ κ²½μ° μ λλ©μ΄μ μ΄ μ€νλμ§ μμ΅λλ€.
/* [ μ λλ©μ΄μ μ΄ μ¬μλμ§ μλ κ²½μ° ] */ animation-duration: 0; /* μ¬μμκ°μ΄ 0μΈ κ²½μ° */ animation-duration: -3s; /* μ¬μμκ°μ΄ μμμΈ κ²½μ° */ /* [ μ λλ©μ΄μ μ΄ μ¬μλλ κ²½μ° ] */ animation-duration: 3s; /* μ¬μμκ°μ΄ μμμΈ κ²½μ° */ animation-duration: 500ms; /* 1μ΄ μ΄νμ μ¬μμκ°μ μ λ ₯ν κ²½μ° */
duration μμ±μ κ²°κ³Όλ μλμ μ 체 μ½λλ₯Ό ν΅ν΄ νμΈν μ μμ΅λλ€.
<!DOCTYPE html> <html> <head> <style> @keyframes yoon { from {transform: translate(100px, 0);} to {transform: translate(300px, 0);} } div { position: absolute; margin: 50px; width: 100px; height: 100px; background-color: #ff0000; /* μ λλ©μ΄μ μ΄λ¦ */ animation-name: yoon; } /* [ μ¬μμκ°μ΄ 0μΈ κ²½μ° ] */ .duration_0s { top: 20px; animation-duration: 0; } /* [ μ¬μμκ°μ΄ μμμΈ κ²½μ° ] */ .duration_minus { top: 130px; animation-duration: -3s; } /* [ μ¬μμκ°μ΄ μμμΈ κ²½μ° ] */ .duration_plus { top: 240px; animation-duration: 3s; } /* [ 1μ΄ μ΄νμ μ¬μμκ°μ μ λ ₯ν κ²½μ° ] */ .duration_ms { top: 350px; animation-duration: 500ms; } </style> </head> <body> <div class="duration_0s">0s</div> <div class="duration_minus">minus</div> <div class="duration_plus">plus</div> <div class="duration_ms">ms</div> </body> </html>
- animation-iteration-count
μμ duration μ½λ μμ λ₯Ό μ€νμν€λ©΄ μ λλ©μ΄μ
μ΄ 1ν μ¬μ ν μ’
λ£λλ κ²μ μ μ μμ΅λλ€. iteration-count μμ±μ μ λλ©μ΄μ
μ μ¬μνλ νμλ₯Ό μ§μ ν λ μ¬μ©ν©λλ€. iteration-count μμ±μ κΈ°λ³Έ κ°μ
1
μ΄λ©°, 0μΌλ‘ κ°μ μ§μ ν κ²½μ° μ λλ©μ΄μ μ΄ μ¬μλμ§ μμ΅λλ€. μμλ‘ μμ± κ°μ μ§μ ν κ²½μ° κΈ°λ³Έ κ°μΈ 1κ³Ό κ°μ κ²°κ³Όλ₯Ό μΆλ ₯νκ³ , μμ°μκ° μλ μμ μ 리μ(ex. 1.5)λ‘ μμ± κ°μ μ§μ ν κ²½μ° μ λλ©μ΄μ μ¬μ λμ€ μ²« λ²μ§Έ νλ μμΌλ‘ λμκ° μ’ λ£λ©λλ€.infinite
λ‘ κ°μ μ€μ ν κ²½μ° μ λλ©μ΄μ μ 무ν λ°λ³΅ν μ μμ΅λλ€.
/* [ μ λλ©μ΄μ μ΄ μ¬μλμ§ μλ κ²½μ° ] */ animation-iteration-count: 0; /* μ¬μνμκ° 0μΈ κ²½μ° */ animation-iteration-count: -3; /* μ¬μνμκ° μμμΈ κ²½μ° */ /* [ μ λλ©μ΄μ μ΄ μ¬μλλ κ²½μ° ] */ animation-iteration-count: 3; /* μ¬μνμκ° μμμΈ κ²½μ° */ animation-iteration-count: 1.5; /* μ¬μνμκ° μ€μμΈ κ²½μ° */ animation-iteration-count: infinite; /* μ λλ©μ΄μ μ 무ν λ°λ³΅ν κ²½μ° */
iteration-count μμ±μ κ²°κ³Όλ μλμ μ 체 μ½λλ₯Ό ν΅ν΄ νμΈν μ μμ΅λλ€.
<!DOCTYPE html> <html> <head> <style> @keyframes yoon { from {transform: translate(100px, 0);} to {transform: translate(300px, 0);}} div { position: absolute; margin: 50px; width: 100px; height: 100px; background-color: #ff0000; /* μ λλ©μ΄μ μμ± */ animation-name: yoon; animation-duration: 1s; } /* [ μ¬μνμκ° 0μΈ κ²½μ° ] */ .iteration-count_0 { top: 20px; animation-iteration-count: 0; } /* [ μ¬μνμκ° μμμΈ κ²½μ° ] */ .iteration-count_minus { top: 130px; animation-iteration-count: -3; } /* [ μ¬μνμκ° μμμΈ κ²½μ° ] */ .iteration-count_plus { top: 240px; animation-iteration-count: 3; } /* [ μ¬μνμκ° μ 리μμΈ κ²½μ° ] */ .iteration-count_rational { top: 350px; animation-iteration-count: 1.5; } /* [ μ λλ©μ΄μ μ 무ν λ°λ³΅ν κ²½μ° ] */ .iteration-count_infinite { top: 460px; animation-iteration-count: infinite; } </style> </head> <body> <div class="iteration-count_0">0</div> <div class="iteration-count_minus">minus</div> <div class="iteration-count_plus">plus</div> <div class="iteration-count_rational">rational</div> <div class="iteration-count_infinite">infinite</div> </body> </html>
- animation-direction
μ λλ©μ΄μ
μ μ¬μ λ°©ν₯μ μ€μ ν λ direction μμ±μ μ¬μ©ν©λλ€. direction μμ±μ κΈ°λ³Έ κ°μ
from
λλ0%
μ μ€μ λ μ€νμΌμμto
λλ100%
μ μ€μ λ μ€νμΌλλ‘ μ¬μνλnormal
μ λλ€. direction μμ±μ μ’ λ₯λ λ€μκ³Ό κ°μ΅λλ€.
animation-direction: normal; /* μλ°©ν₯ μ¬μ */ animation-direction: reverse; /* μλ°©ν₯ μ¬μ */ animation-direction: alternate; /* μλ°©ν₯ μμ, μλ°©ν₯-μλ°©ν₯ λ²κ°μ μ¬μ */ animation-direction: alternate-reverse; /* μλ°©ν₯ μμ, μλ°©ν₯-μλ°©ν₯ λ²κ°μ μ¬μ */
alternateμ alternate-reverseλ μλ‘ λ°λμ κ²°κ³Όλ₯Ό 보μ¬μ€λλ€.
alternate
μ μλ°©ν₯μΌλ‘ μ λλ©μ΄μ
μ μμν΄ μ€ν νμκ° νμμΌ λμλ μλ°©ν₯μΌλ‘, μ§μμΌ λμλ μλ°©ν₯μΌλ‘ μ¬μν©λλ€. λ°λ©΄, alternate-reverse
μ μλ°©ν₯μΌλ‘ μ λλ©μ΄μ
μ μμν΄ μ€ν νμκ° νμμΌ λμλ μλ°©ν₯μΌλ‘, μ§μ μΌ λμλ μλ°©ν₯μΌλ‘ μ¬μν©λλ€.
direction μμ±μ κ²°κ³Όλ μλμ μ 체 μ½λμμ νμΈν μ μμ΅λλ€.<!DOCTYPE html> <html> <head> <style> @keyframes yoon { from {transform: translate(100px, 0);} to {transform: translate(300px, 0);}} div { position: absolute; margin: 50px; width: 100px; height: 100px; background-color: #ff0000; /* μ λλ©μ΄μ μμ± */ animation-name: yoon; animation-duration: 1s; animation-iteration-count: infinite;} /* [ μλ°©ν₯ μ¬μ ] */ .direction_normal { top: 20px; animation-direction: normal;} /* [ μλ°©ν₯ μ¬μ ] */ .direction_reverse { top: 130px; animation-direction: reverse} /* [ μλ°©ν₯ μμ, μλ°©ν₯-μλ°©ν₯ λ²κ°μ μ¬μ ] */ .direction_alternate { top: 240px; animation-direction: alternate;} /* [ μλ°©ν₯ μμ, μλ°©ν₯-μλ°©ν₯ λ²κ°μ μ¬μ ] */ .direction_alternate-reverse { top: 350px; animation-direction: alternate-reverse;} </style> </head> <body> <div class="direction_normal">normal</div> <div class="direction_reverse">reverse</div> <div class="direction_alternate">alternate</div> <div class="direction_alternate-reverse">alternate-reverse</div> </body> </html>
- animation-timing-function
timing-functionμ μ λλ©μ΄μ
@keyframes
μ¬μ΄μ μ¬μ μλλ₯Ό μ‘°μ νλ μμ±μΌλ‘, transion-timing-function μμ±κ³Ό μ μ¬ν κ²°κ³Όλ₯Ό μ 곡ν©λλ€. timing-function μμ±μ μ’ λ₯λ‘λease, linear, ease-in, ease-out, ease-in-out, cubic-bezier(n, n, n, n)
λ±μ΄ μμ΅λλ€.
[ κ°μ μ λλ©μ΄μ κ²°κ³Όλ₯Ό μΆλ ₯νλ μμ±κ° ] animation-timing-function: ease; /* κΈ°λ³Έκ° */ animation-timing-function: cubic-bazier(0,25, 0.1, 0.25, 1); animation-timing-function: linear; animation-timing-function: cubic-bazier(0,0,1,1); animation-timing-function: ease-in; animation-timing-function: cubic-bazier(0.42,0,1,1); animation-timing-function: ease-out; animation-timing-function: cubic-bazier(0,0,0.58,1); animation-timing-function: ease-in-out; animation-timing-function: cubic-bazier(0.42,0,0.58,1);
κ° μμ±κ°μ λν μλ κ·Έλνλ λ€μκ³Ό κ°μΌλ©°, cubic-bezierμ n κ°μ λ°λ₯Έ λ³νλ https://cubic-bezier.com/ μμ νμΈν μ μμ΅λλ€.

- animation-delay
μ λλ©μ΄μ
μμμ μ§μ°μν€κ³ μΆμ κ²½μ°, delay μμ±μ μ¬μ©ν©λλ€. delay μμ±μ κΈ°λ³Έ κ°μ μ λλ©μ΄μ
μ΄ μ§μ° μμ΄ μμλλ
0
λλnow
μ λλ€. κ°μ΄μμ
μΌ κ²½μ° μ§μ λ μκ°μ΄ μ§λ λ€μ μ₯λ©΄λΆν° μ§μ° μμ΄ μ λλ©μ΄μ μ΄ μμλ©λλ€.
animation-delay: 0; /* λ°λ‘ μ¬μ */ animation-delay: now; /* λ°λ‘ μ¬μ */ animation-delay: 1.5s; /* μ§μ° μ¬μ */ animation-delay: -500ms; /* μ§μ μκ° μ΄ν νλ μλΆν° λ°λ‘ μ¬μ */
delay μμ±μ κ²°κ³Όλ μλμ μ 체 μ½λμμ νμΈν μ μμ΅λλ€.
<!DOCTYPE html> <html> <head> <style> @keyframes yoon { from {transform: translate(100px, 0)} to {transform: translate(300px, 0);}} div { position: absolute; margin: 50px; width: 100px; height: 100px; background-color: #ff0000; /* μ λλ©μ΄μ μμ± */ animation-name: yoon; animation-duration: 1s; animation-iteration-count: 1;} /* [ λ°λ‘ μ¬μ ] */ .delay_0 { top: 20px; animation-delay: 0;} /* [ λ°λ‘ μ¬μ ] */ .delay_now { top: 130px; animation-delay: now;} /* [ μ§μ° μ¬μ ] */ .delay_plus { top: 240px; animation-delay: 1.5s;} /* [ μ§μ μκ° μ΄ν νλ μλΆν° λ°λ‘ μ¬μ ] */ .delay_minus { top: 350px; animation-delay: -500ms;} </style> </head> <body> <div class="delay_0">0</div> <div class="delay_now">now</div> <div class="delay_plus">plus</div> <div class="delay_minus">minus</div> </body> </html>
- animation-play-state
μ¬μμ¬λΆλ₯Ό μ€μ ν κ²½μ° play-state μμ±μ μ¬μ©ν©λλ€. μμ±κ°μ΄
running
μΌ κ²½μ° μ λλ©μ΄μ μ μ¬μνκ³ ,paused
μΌ κ²½μ° μ λλ©μ΄μ μ μ μ§ν©λλ€.
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-3.2.0.min.js"></script> <script type="text/javascript"> $(function () { $('.play').click(function () { $('div').css('animation-play-state', 'running'); }); $('.stop').click(function () { $('div').css('animation-play-state', 'paused'); }); }); </script> <style> @keyframes yoon { from { transform: translate(100px, 0); } to { transform: translate(300px, 0); } } div { position: absolute; margin: 50px; width: 100px; height: 100px; background-color: #ff0000; /* μ λλ©μ΄μ μμ± */ animation-name: yoon; animation-duration: 2s; animation-iteration-count: infinite; } </style> </head> <body> <button class="play">running</button> <button class="stop">paused</button> <div>box</div> </body> </html>
2. μ€νν΄ λ³΄λ©° λ°°μ°λ Keyframe μμ
2.1 λΉλ© μ¬λ¦¬κΈ°
μλ μμ (
002.html
)λ keyframesλ₯Ό μ΄μ©νμ¬ background μ΄λ―Έμ§λ₯Ό animation stepsλ₯Ό μ΄μ©νμ¬ μμ°¨μ μΌλ‘ μμΌλ‘ λκΈ°λ©° λ§μΉ λΉλ©μ΄ μ§μ΄μ§λ κ²μ²λΌ 보μ΄κ² νλ μμ μ
λλ€.<!DOCTYPE html> <html> <head> <style> @keyframes hojun { from{ background-position: 0px, 0px; } to { background-position: -3730px, 0; } } .building1{ width: 110px; height: 180px; background: url(./animation/building/building1.png) no-repeat; animation: hojun 5s steps(33); animation-fill-mode: forwards; } </style> </head> <body> <div class="building1"></div> </body> </html>
μ΄ μμ λ₯Ό μ€νμν€λ©΄ μλμ κ°μ μ΄λ―Έμ§κ° μμ°¨μ μΌλ‘ 5μ΄μ μκ° κ°κ²©μ κ°μ§κ³ μΈμμ§λ κ²μ²λΌ 보μ΄λ κ²μ μ μ μμ΅λλ€.

μ΄ μ½λμμ
from
κ³Ό to
λ 0%μ 100%μ
λλ€. μ¬κΈ°μ background-position: -3730px, 0
κ°μ΄ to
μ μλ μ΄μ λ μ΄λ―Έμ§κ° μΌμͺ½ μλ¨μ 0, 0μμ μμΌλ‘ νλμ μ₯λ©΄μ΄ λμ΄κ°λ©° μ΄λ―Έμ§μ Positionμ κ²°κ΅ λ§μ΄λμ€μ κ°μ κ°μ§κ² λκΈ° λλ¬Έμ
λλ€.λ,
animation: hojun 5s steps(33);
μ μ€νμ΄ μλ μ΄μ λ μ΄λ―Έμ§κ° λΆλλ½κ² μμΌλ‘ λμ΄κ°λ κ²μ΄ μλλΌ κ°κ°μ μ₯λ©΄μ΄ λμ΄μ§λ©΄μ 건물μ 보μ¬μ€μΌ νκΈ° λλ¬Έμ κ·Έλ μ΅λλ€.2.2 λΉλ© 2κ° μ¬λ¦¬κΈ°
μλ μμ (
003.html
)λ μμ κ°μ λ°©μμΌλ‘ 2κ°μ 건물μ μ¬λ¦¬λ μ½λμ
λλ€. μ¬κΈ°μ background-positionμ λ§μ΄λμ€ κ°μ μ΄λ―Έμ§μ κΈΈμ΄μ
λλ€. μ€νμ μ΄ λμ΄λ₯Ό κ°κ°μ μ΄λ―Έμ§μ 건물 μ΄λ―Έμ§ λμ΄λ₯Ό λλ κ°μ
λλ€.<!DOCTYPE html> <html> <head> <style> @keyframes one { from{ background-position: 0px, 0px; } to { background-position: -3730px, 0; } } @keyframes two { from{ background-position: 0px, 0px; } to { background-position: -5346px, 0; } } .building1{ width: 110px; height: 180px; background: url(./animation/building/building1.png) no-repeat; animation: one 5s steps(33); animation-fill-mode: forwards; } .building2{ width: 165px; height: 180px; background: url(./animation/building/building2.png) no-repeat; animation: two 5s steps(32); animation-fill-mode: forwards; transform: translate(300px, 300px); } </style> </head> <body> <div class="building1"></div> <div class="building2"></div> </body> </html>
2.3 λΉλ© 3κ°μ λ₯μ΄μ§μ¬λ λ°°μΉ
μ΄λ²μλ μ£ΌμΈκ³΅μΈ λ₯μ΄ μ§μ¬λμ λ°°μΉν΄λ³΄λλ‘ νκ² μ΅λλ€. μ’ λ μμ λ‘μ΄ ν¬μ§μ
λμ μν΄ htmlμ½λλ μλμ κ°μ΄ λ°°μΉνμμ΅λλ€.
<div class="back"> <div class="cat"></div> <div class="building1"></div> <div class="building2"></div> <div class="building7"></div> </div>
μ¬κΈ°μ
back
classμλ relative
μμ±μ μ£Όκ³ κ·Έ μλ μλ div
λ absolute
μμ±μ λΆμ¬νμ¬ μμ λ‘μ΄ λ°°μΉκ° κ°λ₯νλλ‘ νμμ΅λλ€. @keyframes cat { 33.3% { transform: translateY(0) scale(0.3); background: url(./animation/cat/1.png) no-repeat; } 66.6% { transform: translateX(-100px) scale(0.3); background: url(./animation/cat/2.png) no-repeat; } 100% { transform: translateX(-200px) scale(0.3); background: url(./animation/cat/3.png) no-repeat; } }
animation λΆλΆλ§ ν λ² λ³΄λλ‘ νκ² μ΅λλ€.
background
μμ μ΄λ―Έμ§ 3κ°λ₯Ό κ΅μ²΄ν¨μΌλ‘ λ§μΉ λ₯μ΄ μ§μ¬λμ΄ κ±·λ κ²μ²λΌ ꡬννλ € νμμ΅λλ€. μ¬κΈ°μ λ₯μ΄ μ§μ¬λμ΄ κ±Έμ΄μΌ νλ―λ‘ Y
μΆμΌλ‘ μ΄λμ νκ² νμκ³ , λ₯μ΄ μ§μ¬λμ λͺΈμ§μ΄ λ무 컀μ scale(0.3)
μ μμ±μ λΆμ¬νμμ΅λλ€.μλ μ½λλ λͺ¨λ μ½λμ
λλ€.
<!DOCTYPE html> <html> <head> <style> body, img, div{ padding: 0; margin: 0; } @keyframes one { from{ background-position: 0px, 0px; } to { background-position: -3730px, 0; } } @keyframes two { from{ background-position: 0px, 0px; } to { background-position: -5346px, 0; } } @keyframes seven { from{ background-position: 0px, 0px; } to { background-position: -3300px, 0; } } @keyframes cat { 33.3% { transform: translateY(0) scale(0.3); background: url(./animation/cat/1.png) no-repeat; } 66.6% { transform: translateX(-100px) scale(0.3); background: url(./animation/cat/2.png) no-repeat; } 100% { transform: translateX(-200px) scale(0.3); background: url(./animation/cat/3.png) no-repeat; } } .building1{ width: 110px; height: 180px; background: url(./animation/building/building1.png) no-repeat; animation: one 5s steps(33); animation-fill-mode: forwards; transform: scale(0.5); position: absolute; top: 10px; left: 10px; } .building2{ width: 165px; height: 180px; background: url(./animation/building/building2.png) no-repeat; animation: two 5s steps(32); animation-fill-mode: forwards; transform: scale(0.5); position: absolute; top: 300px; left: 300px; } .building7{ width: 150px; height: 180px; background: url(./animation/building/building7.png) no-repeat; animation: seven 5s steps(22); animation-fill-mode: forwards; position: absolute; top: 170px; left: 150px; } .cat{ width: 313px; height: 436px; background: url(./animation/cat.png) no-repeat; animation: cat .5s infinite; transform: scale(0.3); position: absolute; top: 10px; left: 600px; } .back{ width: 100vw; height: 150vh; background-color: YellowGreen; position: relative; } </style> </head> <body> <div class="back"> <div class="cat"></div> <div class="building1"></div> <div class="building2"></div> <div class="building7"></div> </div> </body> </html>
2.4 λΉλ© 3κ°μ λ₯μ΄μ§μ¬λ κ±·κ²νκΈ°
λ€μ νμΌμ(
006.html
) μ νμΌμμ λ₯μ΄ μ§μ¬λμ΄ μ’ λ νμ€μ μΌλ‘ κ±·κ² νλ μ½λμ
λλ€. %λ₯Ό 10%λ‘ λλκ³ λ§μ§λ§μ λ₯μ΄ μ§μ¬λμ΄ μμ°μ€λ½κ² κ±·λ€κ° λ©μΆκ² νμμ΅λλ€.μ’ λ μΈλΆμ μΌλ‘ λ§μμ λ리μλ©΄ κ°μλκ° λΆμ§ μκ² νκΈ° μν΄
animation: cat 3s linear;
λ₯Ό μ£Όμμ΅λλ€. λν λ§μ§λ§μ λ₯μ΄ μ§μ¬λμ λ©μΆκ² νκΈ° μν΄ animation-fill-mode: forwards;
μμ±μ λΆμ¬νμμ΅λλ€.%λ 10%λ‘ λλ κ²μμ
Y
μΆ κ°μ -20px
λ‘ μ£Όμμ΅λλ€.<!DOCTYPE html> <html> <head> <style> body, img, div{ padding: 0; margin: 0; } @keyframes one { from{ background-position: 0px, 0px; } to { background-position: -3730px, 0; } } @keyframes two { from{ background-position: 0px, 0px; } to { background-position: -5346px, 0; } } @keyframes seven { from{ background-position: 0px, 0px; } to { background-position: -3300px, 0; } } @keyframes cat { 10% { transform: translateY(0) scale(0.3); background: url(./animation/cat/1.png) no-repeat; } 20% { transform: translateX(-20px) scale(0.3); background: url(./animation/cat/2.png) no-repeat; } 30% { transform: translateX(-40px) scale(0.3); background: url(./animation/cat/3.png) no-repeat; } 40% { transform: translateX(-60px) scale(0.3); background: url(./animation/cat/1.png) no-repeat; } 50% { transform: translateX(-80px) scale(0.3); background: url(./animation/cat/2.png) no-repeat; } 60% { transform: translateX(-100px) scale(0.3); background: url(./animation/cat/3.png) no-repeat; } 70% { transform: translateX(-120px) scale(0.3); background: url(./animation/cat/1.png) no-repeat; } 80% { transform: translateX(-140px) scale(0.3); background: url(./animation/cat/2.png) no-repeat; } 90% { transform: translateX(-160px) scale(0.3); background: url(./animation/cat/3.png) no-repeat; } 100% { transform: translateX(-180px) scale(0.3); background: url(./animation/cat/1.png) no-repeat; } } .building1{ width: 110px; height: 180px; background: url(./animation/building/building1.png) no-repeat; animation: one 5s steps(33); animation-fill-mode: forwards; transform: scale(0.5); position: absolute; top: 10px; left: 10px; } .building2{ width: 165px; height: 180px; background: url(./animation/building/building2.png) no-repeat; animation: two 5s steps(32); animation-fill-mode: forwards; transform: scale(0.5); position: absolute; top: 300px; left: 300px; } .building7{ width: 150px; height: 180px; background: url(./animation/building/building7.png) no-repeat; animation: seven 5s steps(22); animation-fill-mode: forwards; position: absolute; top: 170px; left: 150px; } .cat{ width: 313px; height: 436px; background: url(./animation/cat.png) no-repeat; animation: cat 3s linear; animation-fill-mode: forwards; transform: scale(0.3); position: absolute; top: 10px; left: 600px; } .back{ width: 100vw; height: 150vh; background-color: YellowGreen; position: relative; } </style> </head> <body> <div class="back"> <div class="cat"></div> <div class="building1"></div> <div class="building2"></div> <div class="building7"></div> </div> </body> </html>
2.5 μ¬λ¬λΆμ μν κ³Όμ
μ΄λ―Έμ§λ₯Ό νμ©νμ¬ μ’ λ λ€μν μ€ν 리 μ λλ©μ΄μ
μ λ§λ€μ΄λ³΄μΈμ. μΉκ΅¬λ€λ(μ, μ¬μ°, ν λΌ) λ§λκ² νμκ³ , λ무λ λ°°μΉνλ©°, λ³΄λ€ λ§μ 건물λ€λ λ°°μΉν΄λ³΄μμμ€.
λ€νΈμ JSκΉμ§ 곡λΆνμκ³ λ€μ μ΄ μ±ν°λ‘ λμμ 곡λΆν΄λ³΄μλ©΄ μ’ λ λ§μ λμμ΄ λμ€ κ²μ
λλ€.
Β