GiantStepDEV
article thumbnail


μ• λ‹ˆλ©”μ΄μ…˜ 속성은 μ „ν™˜ 효과 속성과 ν•¨κ»˜ CSS3μ—μ„œ μƒˆλ‘œ μΆ”κ°€λλŠ”λ°, μ „ν™˜λ³΄λ‹€ 더 μ •ν™•ν•˜κ³  λΆ€λ“œλŸ½κ²Œ μ œμ–΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.

ν‚€ ν”„λ ˆμž„ μ •μ˜ν•˜κΈ°

  • μ• λ‹ˆλ©”μ΄μ…˜ ν‚€ ν”„λ ˆμž„μ€ μ• λ‹ˆλ©”μ΄μ…˜ λ™μž‘μ„ κ΅¬μ„±ν•˜λŠ” 단계듀을 μ •μ˜ν•˜λŠ” 것 μž…λ‹ˆλ‹€.
  • μš”μ†Œκ°€ μ–΄λ–€ μƒνƒœμ—μ„œ(from) μ–΄λ–€ μƒνƒœλ‘œ λ³€ν•˜λŠ”μ§€(to)λ₯Ό μ •μ˜ ν•©λ‹ˆλ‹€.
@keyframes ν‚€ν”„λ ˆμž„λͺ… {
  from {
  
  }
  to {
  
  }
}
@keyframes ν‚€ν”„λ ˆμž„λͺ… {
  0% {

  }
  50% {

  }
  100% {

  }
}

animation-name 속성

  • animation-name 속성은 νŠΉμ • μš”μ†Œμ—μ„œ μ μš©ν•  ν‚€ ν”„λ ˆμž„λͺ…을 μ§€μ • ν•©λ‹ˆλ‹€.
animation-name: ν‚€ν”„λ ˆμž„λͺ…;

animation-duration 속성

  • μ• λ‹ˆλ©”μ΄μ…˜ 지속 μ‹œκ°„ μ„€μ •
animation-duration: μ§€μ†μ‹œκ°„;

animation-delay 속성

  • μ• λ‹ˆλ©”μ΄μ…˜ μ‹€ν–‰ μ§€μ—° μ‹œκ°„ μ§€μ •
animation-delay: μ§€μ—°μ‹œκ°„;

animation-iterator-count 속성

  • μ• λ‹ˆλ©”μ΄μ…˜μ€ 기본으둜 1회 μ‹€ν–‰λ˜κ³  μ’…λ£Œλ©λ‹ˆλ‹€.
  • 상황에 따라 μ• λ‹ˆλ©”μ΄μ…˜μ„ λ°˜λ³΅ν•΄μ„œ λ³΄μ—¬μ€˜μ•Ό ν•˜λŠ” κ²½μš°μ— μ‚¬μš© ν•©λ‹ˆλ‹€.
κΈ°λ³Έ ν˜•νƒœ)
animation-iteration-count: 횟수;
λ¬΄ν•œ 반볡)
animation-iteration-count: infinite;

animation-play-state 속성

  • μ• λ‹ˆλ©”μ΄μ…˜μ˜ μž¬μƒ μƒνƒœλ₯Ό μ§€μ •ν•©λ‹ˆλ‹€.

paused : μ• λ‹ˆλ©”μ΄μ…˜μ˜ 싀행을 μΌμ‹œ μ •μ§€ ν•©λ‹ˆλ‹€.

running : μ• λ‹ˆλ©”μ΄μ…˜μ„ μ‹€ν–‰ν•©λ‹ˆλ‹€.

 

μ „ν™˜ 효과 속성과 λ‹€λ₯΄κ²Œ μ• λ‹ˆλ©”μ΄μ…˜μ€ 속성과 μ‹€ν–‰ 도쀑 μΌμ‹œ μ •μ§€ν•˜κ±°λ‚˜ μž¬μ‹€ν–‰ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

ν•΄λ‹Ή κΈ°λŠ₯은 μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ κΈ°λŠ₯이 ν•„μš” ν•©λ‹ˆλ‹€.

 

animation-direction 속성

  • μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ§„ν–‰ λ°©ν–₯ μ§€μ •

animation μ†μ„±μœΌλ‘œ ν•œλ²ˆμ— μ§€μ •ν•˜κΈ°

  • 속성값은 μ „λΆ€ λ‹€ 적을 ν•„μš”λŠ” μ—†κ³ ,  ν•„μš”ν•œ ν•­λͺ©λ§Œ 적어도 λ©λ‹ˆλ‹€.

예제1

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .container {
      width: 100px;
      height: 100px;
      background-color: antiquewhite;
      /* λ¬΄ν•œλ°˜λ³΅ */
      animation-iteration-count: infinite;
      animation-name: bgChange;
      animation-duration: 5s;
    }
    @keyframes bgChange {
      0% {background-color: red;}
      25% {background-color: orange;}
      50% {background-color: yellow;}
      100% {background-color: green;}
    }
  </style>
</head>
<body>
  <div class="container"></div>
</body>
</html>

예제2

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    #container {
      width: 500px;
      /* top, bottom 20px / autoλŠ” 쒌우 쀑간 μ •λ ¬ */
      margin: 20px auto;
    }
    .box {
      width: 100px;
      height: 100px;
      float: left;
      margin: 50px;
    }
    #box1 {
      background-color: #4cff00;
      border: 1px solid transparent;
      animation-name: shape;
      animation-duration: 3s;
      animation-iteration-count: 10;
    }
    #box2 {
      background-color: #8f06b0;
      border: 1px solid transparent;
      animation-name: rotate;
      animation-duration: 3s;
      animation-iteration-count: 10;
    }
    @keyframes shape {
      from {
        border: 1px solid transparent;
      }
      to {
        border: 1px solid #000;
        border-radius: 50%;
      }
    }
    @keyframes rotate {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(45deg);
      }
    }
  </style>
</head>
<body>
  <div id="container">
    <div class="box" id="box1"></div>
    <div class="box" id="box2"></div>
  </div>
</body>
</html>

 

예제3

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>μ• λ‹ˆλ©”μ΄μ…˜ μΌμ‹œ μ •μ§€, μž¬μ‹€ν–‰</title>
  <style>
    div {
      width: 100px;
      height: 100px;
      background-color: red;
      position: relative;
      animation-name: move;
      animation-duration: 10s;
      animation-fill-mode: forwards;
      animation-play-state: paused;
    }
    @keyframes move {
      from {
        left: 0;
      }
      to {
        left: 300px;
      }
    }
  </style>
</head>
<body>
  <div>
    <button id="start">μ‹œμž‘</button>
    <button id="paused">μΌμ‹œμ •μ§€</button>
  </div>
  <script>
    const box = document.querySelector("div");
    document.getElementById("start").addEventListener("click", function() {
      box.style.animationPlayState = "running";
    })
    document.getElementById("paused").addEventListener("click", function() {
      box.style.animationPlayState = "paused";
    })
  </script>
</body>
</html>
profile

GiantStepDEV

@kongmi

ν¬μŠ€νŒ…μ΄ μ’‹μ•˜λ‹€λ©΄ "μ’‹μ•„μš”β€οΈ" λ˜λŠ” "κ΅¬λ…πŸ‘πŸ»" ν•΄μ£Όμ„Έμš”!