λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
HTML5 & CSS3

[HTML5 & CSS3] μ• λ‹ˆλ©”μ΄μ…˜

by μ½”λ”©ν•˜λŠ” λΆ•μ–΄ 2021. 2. 14.
λ°˜μ‘ν˜•

β–Ά μ• λ‹ˆλ©”μ΄μ…˜

​

*CSS와 μ• λ‹ˆλ©”μ΄μ…˜

CSS3의 animation 속성을 μ‚¬μš©ν•˜λ©΄ μžλ°”μŠ€ν¬λ¦½νŠΈλ‚˜ ν”Œλž˜μ‹œλ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šκ³ λ„ μ›Ή μš”μ†Œμ— μ• λ‹ˆλ©”μ΄μ…˜μ„ μΆ”κ°€ν•  수 μžˆλ‹€. CSS μ• λ‹ˆλ©”μ΄μ…˜μ€ μ‹œμž‘ν•΄μ„œ λλ‚΄λŠ” λ™μ•ˆ μ›ν•˜λŠ” κ³³ μ–΄λ””μ„œλ“  μŠ€νƒ€μΌμ„ λ°”κΎΈλ©° μ• λ‹ˆλ©”μ΄μ…˜μ„ μ •μ˜ν•  수 μžˆλ‹€λŠ” 점으느 νŠΈλžœμ§€μ…˜κ³Ό λ‹€λ₯΄λ‹€. 이 λ•Œ μ• λ‹ˆλ©”μ΄μ…˜ 쀑간에 μŠ€νƒ€μΌμ΄ λ°”λ€ŒλŠ” 지점을 ν‚€ν”„λ ˆμž„(keyframe)이라고 λΆ€λ₯Έλ‹€.

​

속성

μ„€λͺ…

@keyframes

μ• λ‹ˆλ©”μ΄μ…˜μ΄ λ°”λ€ŒλŠ” 지점을 μ„€μ •ν•œλ‹€.

animation-delay

μ• λ‹ˆλ©”μ΄μ…˜ 지연 μ‹œκ°„μ„ μ§€μ •ν•œλ‹€.

animation-direction

μ• λ‹ˆλ©”μ΄μ…˜ μ’…λ£Œ ν›„ μ²˜μŒλΆ€ν„° μ‹œμž‘ν• μ§€, μ—­λ°©ν–₯으둜 진행할지λ₯Ό μ§€μ •ν•œλ‹€.

animation-duration

μ• λ‹ˆλ©”μ΄μ…˜ μ‹€ν–‰ μ‹œκ°„μ„ μ„€μ •ν•œλ‹€.

animation-fill-mode

μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ’…λ£Œλ˜μ—ˆκ±°λ‚˜ μ§€μ—°λ˜μ–΄ μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ‹€ν–‰λ˜μ§€ μ•ŠλŠ” μƒνƒœμΌ λ•Œ μš”μ†Œμ˜ μŠ€νƒ€μΌμ„μ§€μ •ν•œλ‹€.

animation-iteration-count

μ• λ‹ˆλ©”μ΄μ…˜ 반볡 횟수λ₯Ό μ§€μ •ν•œλ‹€.

animation-name

@keyframes둜 μ„€μ •ν•΄ 놓은 쀑간 μƒνƒœμ˜ 이름을 μ§€μ •ν•œλ‹€.

animation-play-state

μ• λ‹ˆλ©”μ΄μ…˜μ„ λ©ˆμΆ”κ±°λ‚˜ λ‹€μ‹œ μ‹œμž‘ν•œλ‹€.

animation-timing-function

μ• λ‹ˆλ©”μ΄μ…˜μ˜ 속도 곑선을 μ§€μ •ν•œλ‹€.

animation

animation ν•˜μœ„ 속성듀을 ν•œκΊΌλ²ˆμ— λ¬Άμ–΄ μ§€μ •ν•œλ‹€.

​

​

​

*@keyframes 속성 - μ• λ‹ˆλ©”μ΄μ…˜ 지점 μ„€μ •ν•˜κΈ°

μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ 지점을 ν‚€ν”„λ ˆμž„μ΄λΌκ³  ν•œλ‹€. μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œμž‘κ³Ό 끝을 λΉ„λ‘―ν•΄ μƒνƒœκ°€ λ°”λ€ŒλŠ” 뢀뢄이 μžˆλ‹€λ©΄ @keyframes 속성을 μ΄μš©ν•΄ λ°”λ€ŒλŠ” 지점을 μ„€μ •ν•œλ‹€.

​

κΈ°λ³Έν˜•)

@keyframes <이름> { <μ„ νƒμž> { <μŠ€νƒ€μΌ> } }

 

μ‚¬κ°ν˜•μ—μ„œ μ›μœΌλ‘œ μ„œμ„œνžˆ λ°”λ€ŒλŠ” μ• λ‹ˆλ©”μ΄μ…˜

<style>
   div {
      width: 100px;
      height: 100px;
      background-color: blue;
      -webkit-animation-name: change-bg;
      -moz-animation-name: change-bg;
      -o-animation-name: change-bg;
      animation-name: change-bg;
      -webkit-animation-duration: 3s;
      -moz-animation-duration: 3s;
      -o-animation-duration: 3s;
      animation-duration: 3s;
   }
   
   @keyframes change-bg {
      from { /* μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μ‹œμ  μŠ€νƒ€μΌ */
         background-color: blue;
         border: 1px solid black;
      }
      
      to { /* μ• λ‹ˆλ©”μ΄μ…˜ 끝 μ‹œμ  μŠ€νƒ€μΌ */
         background-color: #a5d6ff;
         border:1px solid blue;
         border-radius: 50%;
      }
   }
</style>

 

​

​

*animation-name 속성 - μ• λ‹ˆλ©”μ΄μ…˜ 이름 μ§€μ •ν•˜κΈ°

CSS둜 μ• λ‹ˆλ©”μ΄μ…˜μ„ λ§Œλ“€ λ•Œ @keyframes 속성을 μ΄μš©ν•΄ μ—¬λŸ¬ 개의 μ• λ‹ˆλ©”μ΄μ…˜μ„ μ •μ˜ν•˜λŠ”λ° animation-name μ†μ„±μ—μ„œ μ§€μ •ν•œ μ• λ‹ˆλ©”μ΄μ…˜ μ΄λ¦„μœΌλ‘œ κ΅¬λΆ„ν•œλ‹€. 이 animation-name 속성을 μ‚¬μš©ν•˜λ©΄ μ™Όμͺ½ μ†ŒμŠ€λ‘œ μ •μ˜ν•œ μ• λ‹ˆλ©”μ΄μ…˜μ„ 였λ₯Έμͺ½ μ†ŒμŠ€μ²˜λŸΌ animation-name 속성에 change-bgλΌλŠ” 값을 μ μš©ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€.

​

κΈ°λ³Έν˜•)

animation-name: <ν‚€ν”„λ ˆμž„ 이름> | none

 

@keyframe을 μ‚¬μš©ν•΄ μ‹€ν–‰ν•  μ• λ‹ˆλ©”μ΄μ…˜ μ§€μ •ν•˜κΈ°

<style>
   #box1 {
      background-color: #4cff00;
      border: 1px solid black;
      -webkit-animation-name: shape;
      -moz-animation-name: shape;
      -o-animation-name: shape;
      animation-name: shape;
      -webkit-animation-duration: 3s;
      -moz-animation-duration: 3s;
      -o-animation-duration: 3s;
      animation-duration: 3s;
   }
   #box2 {
      background-color: #8f06b0;
      border: 1px solid black;
      -webkit-animation-name: rotate;
      -moz-animation-name: rotate;
      -o-animation-name: rotatboxe;
      animation-name: rotate;
      -webkit-animation-duration: 3s;
      -moz-animation-duration: 3s;
      -o-animation-duration: 3s;
      animation-duration: 3s;
   }
   @keyframes shape { /* λͺ¨μ–‘이 λ°”λ€ŒλŠ” μ• λ‹ˆλ©”μ΄μ…˜ */
      from {
         border: 1px solid black;
      }
      to {
         border: 1px solid black;
         border-radius: 50%;
      }
   }
   @keyframes rotate { /* νšŒμ „ν•˜λŠ” μ• λ‹ˆλ©”μ΄μ…˜ */
      from {
         transform:rotate(0deg)
      }
      to {
         transform: rotate(45deg);
      }
   }
</style>

 

​

​

*animation-duration 속성 - μ• λ‹ˆλ©”μ΄μ…˜ μ‹€ν–‰ μ‹œκ°„ μ„€μ •ν•˜κΈ°

animation-duration 속성은 μ• λ‹ˆλ©”μ΄μ…˜μ„ μ–Όλ§ˆ λ™μ•ˆ μž¬μƒν•  것인지 μ„€μ •ν•œλ‹€. μ‚¬μš©ν•  수 μžˆλŠ” 값은 초(s)λ‚˜ λ°€λ¦¬μ΄ˆ(ms)둜 ν‘œμ‹œν•œ μ‹œκ°„ 값이닀. κΈ°λ³Έ 값은 0이기 λ•Œλ¬Έμ— animation-duration 속성 값을 μ •ν•˜μ§€ μ•ŠμœΌλ©΄ μ• λ‹ˆλ©”μ΄μ…˜μ€ μΌμ–΄λ‚˜μ§€ μ•ŠλŠ”λ‹€.

​

κΈ°λ³Έν˜•)

animation-duration: <μ‹œκ°„>

 

​

​

*animation-direction 속성 - μ• λ‹ˆλ©”μ΄μ…˜ λ°©ν–₯ μ§€μ •ν•˜κΈ°

기본적으둜 μ• λ‹ˆλ©”μ΄μ…˜μ΄ ν•œ 번 μ‹€ν–‰λ˜λ©΄ μ›λž˜ μœ„μΉ˜λ‘œ λ˜λŒμ•„κ°€λŠ”λ° animation-direction 속성을 μ΄μš©ν•˜λ©΄ μ›λž˜ μœ„μΉ˜λ‘œ λ˜λŒμ•„κ°€κ±°λ‚˜ λ°˜λŒ€ λ°©ν–₯으둜 μ• λ‹ˆλ©”μ΄μ…˜μ„ ν•œ 번 더 μ‹€ν–‰ν•  수 μžˆλ‹€.

속성 κ°’

μ„€λͺ…

normal

μ• λ‹ˆλ©”μ΄μ…˜μ„ λκΉŒμ§€ μ‹€ν–‰ν•˜λ©΄ μ›λž˜ 있던 μœ„μΉ˜λ‘œ λŒμ•„κ°„λ‹€.

alternate

μ• λ‹ˆλ©”μ΄μ…˜μ„ λκΉŒμ§€ μ‹€ν–‰ν•˜λ©΄ μ™”λ˜ λ°©ν–₯으둜 λ˜λŒμ•„κ°€λ©΄μ„œ μ• λ‹ˆλ©”μ΄μ…˜μ„ μ‹€ν–‰ν•œλ‹€.

​

​

​

*animation-iteration-count 속성 - 반볡 횟수 μ§€μ •ν•˜κΈ°

기본적으둜 μ• λ‹ˆλ©”μ΄μ…˜μ€ ν•œ 번만 μ‹€ν–‰ν•˜κ³  λλ‚˜λŠ”λ°, 반볡 μ‹€ν–‰ν•  μˆ˜λ„ μžˆλ‹€. κ·ΈλŸ΄λ•Œ animation-iteration-count 속성을 μ‚¬μš©ν•΄ 반볡 횟수λ₯Ό 지정할 수 μžˆλ‹€.

λ¬΄ν•œ λ°˜λ³΅ν•˜λŠ” μ• λ‹ˆλ©”μ΄μ…˜ λ§Œλ“€κΈ°

<style>
   .box {
      margin-top: 50px;
      margin-left: 100px;
      padding: 20px;
      height: 60px;
      -webkit-animation-name: moving;
      -moz-animation-name: moving;
      -o-animation-name: moving;
      animation-name: moving;
      -webkit-animation-duration: 3s;
      -moz-animation-duration: 3s;
      -o-animation-duration: 3s;
      animation-duration: 3s;
      -webkit-animation-direction: normal;
      -moz-animation-direction: normal;
      -o-animation-direction: normal;
      animation-direction: normal; /* μ• λ‹ˆλ©”μ΄μ…˜μ΄ λλ‚œ ν›„ λ°˜λŒ€ λ°©ν–₯으둜 μ‹€ν–‰ν•˜μ§€ μ•ŠμŒ */
      -webkit-animation-iteration-count: infinite;
      -moz-animation-iteration-count: infinite;
      -o-animation-iteration-count: infinite;
      animation-iteration-count: infinite; ​/* μ• λ‹ˆλ©”μ΄μ…˜μ΄ λλ‚œ ν›„ λ¬΄ν•œ λ°˜λ³΅ν•¨ */
   }
​
   @keyframes moving {
      from {
         width: 200px;
         background: #faef7c;
         opacity: 0.5;
         transform: scale(0.5) rotate(15deg);
      }
      to {
         width: 400px;
         background: #ff9400;
         opacity: 1;
         transform: scale(1) rotate(0deg);
      }
   }
</style>

<body>
<div class="box">
<h3>CSS3 Animation</h3>
</div>
</body>

 

​

​

*animation-timing-function 속성 - μ• λ‹ˆλ©”μ΄μ…˜ 속도 곑선 μ§€μ •ν•˜κΈ°

νŠΈλžœμ§€μ…˜κ³Ό λ§ˆμ°¬κ°€μ§€λ‘œ μ• λ‹ˆλ©”μ΄μ…˜μ—μ„œλ„ μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œμž‘κ³Ό 쀑간, λμ—μ„œμ˜ 속도λ₯Ό 선택해 전체적인 속도 곑선을 지정할 수 μžˆλ‹€.

​

κΈ°λ³Έν˜•)

animation-timing-function: linear | ease | ease-in | ease-out | ease-in-out | cubic-bezier(n, n, n, n)

 

​

​

*animation 속성 - μ• λ‹ˆλ©”μ΄μ…˜ κ΄€λ ¨ 속성 ν•œκΊΌλ²ˆμ— ν‘œκΈ°ν•˜κΈ°

κΈΈκ³  λ³΅μž‘ν•œ μ• λ‹ˆλ©”μ΄μ…˜ κ΄€λ ¨ 속성듀도 animation 속성을 μ‚¬μš©ν•˜λ©΄ κ°„λ‹¨νžˆ ν•œ μ€„λ‘œ ν‘œκΈ°ν•  수 μžˆλ‹€.

μ΄λ ‡κ²Œ κ°„λž΅νžˆ ν‘œκΈ°ν•΄ κΈ°λ³Έ 값을 μ‚¬μš©ν•˜λ”λΌλ„ animation-duration 속성 값은 λ°˜λ“œμ‹œ ν‘œκΈ°ν•΄μ•Ό ν•œλ‹€. μ• λ‹ˆλ©”μ΄μ…˜ μ‹€ν–‰ μ‹œκ°„μ„ μ§€μ •ν•˜μ§€ μ•ŠμœΌλ©΄ κΈ°λ³Έ κ°’ 0이 μ μš©λ˜μ–΄ μ• λ‹ˆλ©”μ΄μ…˜ 효과λ₯Ό λ³Ό 수 μ—†κΈ° λ•Œλ¬Έμ΄λ‹€.

​

κΈ°λ³Έν˜•)

animation :

<animation-name> | <animation-duration> | <animation-timing-function> | <animation-delay> |

<animation-iteration-count> | <animation-direction>

 

두 개 μ΄μƒμ˜ μ• λ‹ˆλ©”μ΄μ…˜ λ™μ‹œμ— μ‹€ν–‰ν•˜κΈ°

<style>
   .box {
      width: 60px;
      height: 60px;
      margin: 60px;
      -webkit-animation: rotate 1.5s infinite, background 1.5s infinite alternate;
      -moz-animation: rotate 1.5s infinite, background 1.5s infinite alternate;
      -o-animation: rotate 1.5s infinite, background 1.5s infinite alternate;
      animation: rotate 1.5s infinite, background 1.5s infinite alternate;
   }
​
   @keyframes rotate { /* 쀑간(50%)에 xμΆ• κΈ°μ€€μœΌλ‘œ νšŒμ „ν•˜κ³  끝날 λ•Œ(100%) yμΆ• κΈ°μ€€μœΌλ‘œ νšŒμ „ν•œλ‹€ */
      from { transform: perspective(120px) rotateX(0deg) rotateY(0deg); }
      50% { transform: perspective(120px) rotateX(-180deg) rotateY(0deg); }
      to { transform: perspective(120px) rotateX(-180deg) rotateY(-180deg); }
   }
​
   @keyframes background { /* μ²˜μŒμ—λŠ” 빨간색 λ°°κ²½μ΄μ—ˆλ‹€κ°€ 쀑간에 μ΄ˆλ‘μƒ‰μœΌλ‘œ 바뀐 ν›„ 끝날 λ•ŒλŠ” νŒŒλž€μƒ‰ λ°°κ²½ */
      from { background: red; }
      50% { background-color: green }
      to { background-color: blue; }
   }
</style>
</head>
​
<body>
<div class="box"></div>
</body>

 

λ°˜μ‘ν˜•

λŒ“κΈ€