GiantStepDEV
article thumbnail

μ „ν™˜?

  • μš”μ†Œ(element)의 속성(property)이 변경될 λ•ŒλΆ€λ“œλŸ½κ²Œλ³€κ²½λ˜λŠ” 효과 제곡
  • 예) μš”μ†Œμ˜ 배경색이 변경될 λ•Œ λ°”λ‘œ λ³€κ²½λ˜λŠ” 것이 μ•„λ‹ˆλΌ 일정 μ‹œκ°„μ΄ μ§€λ‚˜λ©΄ μ„œμ„œνžˆ λ³€κ²½λ˜λŠ” 효과λ₯Ό 쀄 수 μžˆμŠ΅λ‹ˆλ‹€.

μ „ν™˜ νš¨κ³Όκ°€ μ—†λŠ” 경우

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .box1 {
      width: 100px;
      height: 100px;
      background-color: red;
    }
    .box1:hover {
      background-color: blue;
    }
  </style>
</head>
<body>
  <div class="box1"></div>
</body>
</html>

λ­”κ°€ ν—ˆμ „ν•œ λŠλ‚Œ.

 

μ „ν™˜ 효과 μ μš©ν•œ 경우

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .box1 {
      width: 100px;
      height: 100px;
      background-color: red;
      transition-property: all;
      transition-duration: 1s;
      transition-delay: .3s;
    }
    .box1:hover {
      background-color: blue;
    }
  </style>
</head>
<body>
  <div class="box1"></div>
</body>
</html>

μ•„κΉŒλ³΄λ‹€ λΆ€λ“œλŸ¬μš΄ λŠλ‚Œ

 

νŠΈλžœμ§€μ…˜κ³Ό 속성

  • transition-property : νŠΈλžœμ§€μ…˜μ˜ λŒ€μƒ μ§€μ •
  • transition-duration : νŠΈλžœμ§€μ…˜μ„ μ‹€ν–‰ν•  μ‹œκ°„ μ§€μ •
  • transition-delay : νŠΈλžœμ§€μ…˜μ˜ μ§€μ—° μ‹œκ°„ μ§€μ •
  • transition-timing-function : νŠΈλžœμ§€μ…˜μ˜ μ‹€ν–‰ ν˜•νƒœ μ§€μ •
  • transition : 속성 ν•œκΊΌλ²ˆμ— μ§€μ •

πŸ“Œ μ „ν™˜ νš¨κ³ΌλŠ” λ°˜λ“œμ‹œ transition-property 속성과 transition-duration 속성을 ν•¨κ»˜ μ‚¬μš©ν•΄μ•Ό 함.

transition-property 속성

  • νŠΈλžœμ§€μ…˜μ˜ λŒ€μƒ μ§€μ •

transition-properry : [속성값];

  • none : μ „ν™˜ 효과 속성을 μ§€μ •ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
  • all : λͺ¨λ“  속성을 μ „ν™˜ 효과 λŒ€μƒμœΌλ‘œ μ§€μ •ν•©λ‹ˆλ‹€.
  • κ°œλ³„μ μœΌλ‘œ μ§€μ • κ°€λŠ₯ πŸ‘‡

transition-duration 속성

  • νŠΈλžœμ§€μ…˜μ„ μ‹€ν–‰ν•  μ‹œκ°„ μ§€μ •

transition-duration: [μ‹œκ°„];

예) transition-duration: 2s;

transition-delay 속성

  • νŠΈλžœμ§€μ…˜ λ°œμƒ μ§€μ—° μ‹œκ°„ μ§€μ •

transition-timing-function 속성

  • μ „ν™˜ 효과의 μ§„ν–‰ 속도 μ§€μ •
  • μ •ν•΄μ§„ ν‚€μ›Œλ“œμ™€ cubic-bezier() ν•¨μˆ˜(μ‚¬μš©μž μ§€μ •)을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    body {
      margin: 0 auto;
    }
    .red-box {
      background-color: orangered;
      width: 100px;
      height: 100px;
      transition: all;
      transition-duration: 2s;
      transition-delay: .3s;
      margin-bottom: 10px;
    }
    .red-box:hover {
      background-color: blue;
      width: 800px;
    }
    .red-box:nth-child(1) {
      transition-timing-function: linear;
    }
    .red-box:nth-child(2) {
      transition-timing-function: ease;
    }
    .red-box:nth-child(3) {
      transition-timing-function: ease-in;
    }
    .red-box:nth-child(4) {
      transition-timing-function: ease-out;
    }
    .red-box:nth-child(5) {
      transition-timing-function: ease-in-out;
    }
  </style>
</head>
<body>
  <!-- μš”μ†Œμ˜ 속성이 변경될 λ•Œ 'λΆ€λ“œλŸ½κ²Œ' λ³€κ²½λ˜λŠ” 효과 제곡(μ‹œκ°„μ΄ κ°œμž…λ¨) -->
  <div class="red-box">liner</div>
  <div class="red-box">ease</div>
  <div class="red-box">ease-in</div>
  <div class="red-box">ease-out</div>
  <div class="red-box">ease-in-out</div>
</body>
</html>

 

크둬 개발자 λ„κ΅¬μ—μ„œλ„ 확인 κ°€λŠ₯

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

κΈ°λ³Έ ν˜•νƒœ)
transition: property, duration, timing-function, delay;
μ˜ˆμ‹œ)
transition:width, 1s, ease-in, 1s;

μ‹€μŠ΅ 예제 - μƒν’ˆ 정보 ν‘œμ‹œν•˜κΈ°

  • ν•΄λ‹Ή μƒν’ˆμ— 마우슀 μ˜€λ²„μ‹œ μƒν’ˆ 정보 ν‘œμ‹œ ν•˜κΈ°
  • νŠΈλžœμ§€μ…˜ 효과 μ μš©ν•˜κΈ°
  • μƒν’ˆ 1, μƒν’ˆ 2, μƒν’ˆ 3 νƒ€μ΄ν‹€λ§Œ λ‹€λ₯΄κ³  λ‚΄μš©μ„ λ™μΌν•˜κ²Œ
  • opacity: 0; 이면 화면에 보이지 μ•ŠμŒ(투λͺ…도λ₯Ό μ‘°μ •ν•˜λŠ” 속성)

 

μ½”λ“œ

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>μ‹ μƒν’ˆ λͺ©λ‘</title>
  <style>
    #container {
        width: 1000px;
        margin: 20px auto;
    }
    h1 {
        text-align: center;
        font-size: 30px;
    }
    ul {
        list-style: none;
        padding: 0;
    }

    li {
        float: left;
        padding: 0px;
        margin: 10px;
        position: relative;
        overflow: hidden;
    }
    img {
        margin: 0px;
        padding: 0px;
        z-index: 5;
        float: left;
    }

    li .caption {
        position: absolute;
        left: -200px;
        width: 300px;
        height: 200px;
        padding-top: 20px;
        background-color: rgba(0, 0, 0, .6);
        opacity: 0;
        transition: .8s .2s ease-in-out;
        z-index: 10;
    }
    li:hover .caption {
        opacity: 1;
        transform: translateX(200px);
    }

    .caption h2, .caption p {
        color: white;
        text-align: center;
    }
  </style>
</head>
<body>
  <div id="container">
    <h1>μ‹ μƒν’ˆ λͺ©λ‘</h1>
    <ul>
      <li>
        <img src="./images/prod1.jpg" alt="μƒν’ˆ1">
        <div class="caption">
          <h2>μƒν’ˆ1</h2>
          <p>μƒν’ˆ1에 λŒ€ν•œ μ„€λͺ… ν…μŠ€νŠΈ</p>
          <p>가격 : 12,500원</p>
        </div>
      </li>
      <li>
        <img src="./images/prod2.jpg" alt="μƒν’ˆ2">
        <div class="caption">
          <h2>μƒν’ˆ2</h2>
          <p>μƒν’ˆ2에 λŒ€ν•œ μ„€λͺ… ν…μŠ€νŠΈ</p>
          <p>가격 : 20,900원</p>
        </div>
      </li>
      <li>
        <img src="./images/prod3.jpg" alt="μƒν’ˆ3">
        <div class="caption">
          <h2>μƒν’ˆ3</h2>
          <p>μƒν’ˆ3에 λŒ€ν•œ μ„€λͺ… ν…μŠ€νŠΈ</p>
          <p>가격 : 9,000원</p>
        </div>
      </li>
    </ul>
  </div>
</body>
</html>
profile

GiantStepDEV

@kongmi

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