9-2. CSS νŠΈλžœμ§€μ…˜ (transition-property, transition-duration, transition-timing-function, transition-delay)

2021. 10. 15. 18:40ㆍHTML + CSS + JS

728x90

1. νŠΈλžœμ§€μ…˜ transition

νŠΈλžœμ§€μ…˜μ€ μ›Ή μš”μ‡ μ˜ 배경색을 λ°”κΎΈκ±°λ‚˜ λ„ν˜•μ˜ ν…Œλ‘λ¦¬λ₯Ό μ‚¬κ°ν˜•μ—μ„œ μ›ν˜•μœΌλ‘œ λ°–λŠ” κ²ƒμ²˜λŸΌ μŠ€νƒ€μΌμ˜ 속성이 λ°”λ€ŒλŠ” 것을 λ§ν•œλ‹€. 

μ›Ή μš”μ†Œμ˜ μŠ€νƒ€μΌ 속성이 μ‹œκ°„μ— 따라 λ°”λ€ŒλŠ” 것을 νŠΈλžœμ§€μ…˜μ΄λΌκ³  ν•œλ‹€. 

μ›ν˜•μœΌλ‘œ λ°”λ€œ 

 

2. transtion-property 

transition-property 속성은 νŠΈλžœμ§€μ…˜ λŒ€μƒμ„ μ§€μ •ν•˜λŠ” 속성이닀. 

 

1️⃣ all : λͺ¨λ“  속성이 νŠΈλžœμ§€μ…˜ λŒ€μƒμ΄ λœλ‹€. κΈ°λ³Έκ°’ 

2️⃣ none : νŠΈλžœμ§€μ…˜μ„ ν•˜λŠ” λ™μ•ˆ 아무 속성도 λ°”λ€Œμ§€ μ•ŠλŠ”λ‹€. 

3️⃣ 속성 이름 : νŠΈλžœμ§€μ…˜ 효과λ₯Ό μ μš©ν•  속성을 μ§€μ •ν•œλ‹€. 

 

 

3. transition-duration

transition-duration은 transtion-property μ—μ„œ νŠΈλžœμ§€μ…˜ λŒ€μƒμ„ μ§€μ •ν–ˆλ‹€λ©΄ λ‹€μŒμœΌλ‘œ 진행 μ‹œκ°„μ„ 지정해야 속성이 μžμ—°μŠ€λŸ½κ²Œ λ°”λ€ŒλŠ” μ• λ‹ˆλ©”μ΄μ…˜ 효과λ₯Ό λ§Œλ“€ 수 μžˆλ‹€. 

지정할 수 μžˆλŠ” λ‹¨μœ„λŠ” 초 λ˜λŠ” λ°€λ¦¬μ΄ˆμ΄λ‹€. 

νŠΈλžœμ§€μ…˜ λŒ€μƒ 속성이 μ—¬λŸ¬κ°œ 라면 진행 μ‹œκ°„λ„ μ‰Όν‘œλ‘œ κ΅¬λΆ„ν•΄μ„œ μ—¬λŸ¬κ°œ 지정할 수 μžˆλ‹€. 

transition-duration : μ‹œκ°„ 

νŠΈλžœμ§€μ…˜ μ‹œκ°„μ€ λ„ˆλΉ„λŠ” 2초 λ†’μ΄λŠ” 1초 

 

 

4. transition-timing-function 

transition-timing-function 속성은 νŠΈλžœμ§€μ…˜ 속도 곑선을 μ§€μ •ν•˜λŠ” 속성이닀. 

이 속성을 μ‚¬μš©ν•˜λ©΄ νŠΈλžœμ§€μ…˜ 효과의 μ‹œμž‘,쀑간, λμ—μ„œ 속도λ₯Ό 지정해 전체 속도 곑선을 λ§Œλ“€ 수 μžˆλ‹€. 

 

1️⃣ ease : μ²˜μŒμ—λŠ” 천천히 μ‹œμž‘ν•˜κ³  점점 빨라지닀가 λ§ˆμ§€λ§‰μ—” 천천히 끝낸닀.  κΈ°λ³Έκ°’ 

2️⃣ linear: μ‹œμž‘λΆ€ν„° λκΉŒμ§€ λ˜‘κ°™μ€ μ†λ„λ‘œ μ§„ν–‰ν•œλ‹€. 

3️⃣ ease-in : 느리게 μ‹œμž‘ν•œλ‹€. 

4️⃣ ease-out: 느리게 끝낸닀. 

5️⃣ ease-in-out : 느리게 μ‹œμž‘ν•˜κ³  느리게 끝낸닀. 

6️⃣ cubic-bezier(n, n, n, n) : 배지에 ν•¨μˆ˜λ₯Ό μ •μ˜ν•΄μ„œ μ‚¬μš©ν•œλ‹€. μ΄λ•Œ n 값은 0~1 μ‚¬μ΄λ§Œ μ‚¬μš©ν•  수 μžˆλ‹€. 

 

느리게 μ‹œμž‘ν•˜κ³  느리게 끝낸닀. 

 

5. transition-delay 

transition-delay 속성은 νŠΈλžœμ§€μ…˜ 효과λ₯Ό μ–Έμ œλΆ€ν„° μ‹œμž‘ν•  것인지 μ„€μ •ν•œλ‹€. 

이 속성을 μ‚¬μš©ν•˜λ©΄ μ§€μ •ν•œ μ‹œκ°„λ§ŒνΌ κΈ°λ‹€λ Έλ‹€κ°€ νŠΈλžœμ§€μ…˜μ΄ μ‹œμž‘λ¨. 

transition-delay : μ‹œκ°„ 

 

 

* μ—°μŠ΅λ¬Έμ œ 1

마우슀 올리면 κΈ€ 이 보이도둝 μ„€μ • 

 

html 

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
  <title>CSS3 μ• λ‹ˆλ©”μ΄μ…˜</title>
  <link rel="stylesheet" href="css/product.css">
</head>
<body>
	<div id="container">
    <h1>μ‹ μƒν’ˆ λͺ©λ‘</h1>
		<ul class="prod-list">
      <li>
        <img src="images/prod1.jpg">
        <div class="caption">
          <h2>μƒν’ˆ 1</h2>
          <p>μƒν’ˆ 1 μ„€λͺ… ν…μŠ€νŠΈ</p>
          <p>가격 : 12,345원</p>
        </div>
      </li>
      <li>
        <img src="images/prod2.jpg">
        <div class="caption">
          <h2>μƒν’ˆ 2</h2>
          <p>μƒν’ˆ 2 μ„€λͺ… ν…μŠ€νŠΈ</p>
          <p>가격 : 12,345원</p>
        </div>
      </li>
      <li>
        <img src="images/prod3.jpg">
        <div class="caption">
          <h2>μƒν’ˆ 3</h2>
          <p>μƒν’ˆ 3 μ„€λͺ… ν…μŠ€νŠΈ</p>
          <p>가격 : 12,345원</p>
        </div>
      </li>
    </ul>
	</div>
</body>
</html>

CSS

#container {
  width:1000px;
  margin:20px auto;
}
h1 {
  text-align:center;
}
.prod-list {
  list-style:none;
  padding:0;
}
.prod-list li {
  float: left;
  padding: 0;
  margin: 10px;
  overflow: hidden;
  position: relative;
}
.prod-list img {
  margin:0;
  padding:0;
  float:left;
  z-index:5;
} 
.prod-list .caption {
  top: 200px;
  width: 300px;
  height: 200px;
  position: absolute;
  padding-top: 20px;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: all 0.6s ease-in-out;
  z-index: 10;

}

.prod-list li:hover .caption {
  opacity: 1;
  transform : translateY(-200px);
}

.prod-list .caption h2, .prod-list .caption p {
  color: #fff;
  text-align: center;
}

 

 

 

 

 

 

 

 

 

 

728x90