็ก์
transition ์์ฑ ๋ณธ๋ฌธ
๐ข transition
์์์ ์คํ์ผ์ด ๋ณํ ๋, ๋ณํ ๊ณผ์ ์ ์ผ์ ์๊ฐ ๋์ ์ ์ง์ ์ผ๋ก ๋ถ๋๋ฝ๊ฒ ์ ๋๋ฉ์ด์ ํจ๊ณผ์ฒ๋ผ ๋ณด์ฌ์ฃผ๋ ์์ฑ.
๐ฏ ํต์ฌ ์์ฑ 4๊ฐ์ง ๐ฏ
๐น transition-property
๋ณํ ์ค ๋์ ์์ฑ ์ง์ .
.prop-box {
width: 100px;
height: 100px;
background-color: #e74c3c;
/* ๋ฐฐ๊ฒฝ์(background-color) ๋ณํ์๋ง 1์ด๊ฐ ํจ๊ณผ๋ฅผ ์ค๋๋ค. */
/* ๋๋น(width) ๋ณํ๋ ์ฆ์ ์ผ์ด๋ฉ๋๋ค. */
transition-property: background-color;
transition-duration: 1s;
}
.prop-box:hover {
background-color: #8e44ad;
width: 200px;
}
- ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ: all (์ ์ฒด), background-color, width, height, transform, opacity ๋ฑ
๐น transition-duration [ํ์]
๋ณํ๊ฐ ์ผ์ด๋ ์ง์ ์๊ฐ ์ค์ . (๋จ์: s ๋๋ ms)
.dur-box {
width: 100px;
height: 100px;
background-color: #3498db;
transition-property: transform;
}
.fast { transition-duration: 0.2s; } /* ์์ฃผ ๋น ๋ฅด๊ฒ */
.slow { transition-duration: 2s; } /* ์์ฃผ ๋๋ฆฌ๊ฒ */
.dur-box:hover {
transform: rotate(180deg);
}
- ์ ์์ฑ์ด ์์ผ๋ฉด ์ ๋๋ฉ์ด์ ์ด ์ ๋ณด์.
๐น transition-timing-function
๋ณํ์ ์๋ ๊ณก์ ์ง์ .
.time-box {
width: 100px;
height: 50px;
margin-bottom: 10px;
background-color: #2ecc71;
transition: width 1s; /* ๋จ์ถ ์์ฑ ์ฌ์ฉ */
}
.linear { transition-timing-function: linear; } /* ์ผ์ ํ ์๋ */
.ease-in { transition-timing-function: ease-in; } /* ์์์ ๋๋ฆฌ๊ฒ, ๋์ ๋น ๋ฅด๊ฒ */
.out { transition-timing-function: cubic-bezier(0, 0.5, 0.5, 1); } /* ์ปค์คํ
๊ณก์ */
.container:hover .time-box {
width: 300px;
}
- ์๋์ ๋ณํ ๋ฐฉ์ (๋๋)
- linear: ์ผ์ ํ ์๋๋ก ๋ณํ.
- ease: ๋๋ฆฌ๊ฒ ์์ → ๋น ๋ฅด๊ฒ ์งํ → ๋๋ฆฌ๊ฒ ๋๋จ. (๊ธฐ๋ณธ๊ฐ)
- ease-in: ๋๋ฆฌ๊ฒ ์์ → ๋น ๋ฅด๊ฒ ๋๋จ.
- ease-out: ๋น ๋ฅด๊ฒ ์์ → ๋๋ฆฌ๊ฒ ๋๋จ.
- ease-in-out: ๋๋ฆฌ๊ฒ ์์ → ๋น ๋ฅด๊ฒ ์งํ → ๋๋ฆฌ๊ฒ ๋๋จ.
- cubic-bezier(x1, y1, x2, y2): ์ฌ์ฉ์ ์ ์ ์๋ ๊ณก์ .
๐น transition-delay
๋ณํ๊ฐ ์์๋๊ธฐ ์ ๋๊ธฐ ์๊ฐ ์ค์ . (๋จ์: s)
.delay-box {
width: 100px;
height: 100px;
background-color: #f1c40f;
/* 1์ด๋ฅผ ๊ธฐ๋ค๋ฆฐ ํ์ 0.5์ด ๋์ ๋ณํ๊ฐ ์ผ์ด๋ฉ๋๋ค. */
transition-duration: 0.5s;
transition-delay: 1s;
}
.delay-box:hover {
border-radius: 50%;
background-color: #f39c12;
}โ
- ์ ํ์ฌํญ (์์ฃผ ์ฐ์ง ์์)
๐จ ๋จ์ถ ์์ฑ(Shorthand)
selector {
transition: [property] [duration] [timing-function] [delay];
}
- ๋ฌธ๋ฒ: transition: ์์ฑ ์๊ฐ ํ์ด๋ฐํจ์ ๋๊ธฐ์๊ฐ;
- ์ฃผ์: ์์ฑ ํ๋ ์์์๋ ๊ณต๋ฐฑ, ์ฌ๋ฌ ๊ฐ์ transition์ ๋์ดํ ๋๋ ์ฝค๋ง(,)
๐ฅ ํจ๊ป ์ฌ์ฉํ๋ ์ค์ ์์ฑ ๐ฅ
๐น transform-origin
๋ณํ(transform)์ ๊ธฐ์ค์ (์ค์ฌ์ ), ๋ฐฉ์์ ์ ํ๋ ์์ฑ
.box {
/* ์ผ์ชฝ ์ ๊ผญ์ง์ ์ ๊ธฐ์ค์ผ๋ก ํ์ */
transform-origin: left top;
transform: rotate(45deg);
}
- ๊ธฐ๋ณธ๊ฐ์ ์ ์ค์(50% 50%)์ด์ง๋ง, ์ผ์ชฝ ์๋ ์ค๋ฅธ์ชฝ ์๋ ๋ฑ์ผ๋ก ๋ฐ๊ฟ ์ ์๋ค.
๐โ POINT ๐โ
โ๏ธ duration ์ด ์ค์ ๋์ง ์์ผ๋ฉด ๊ธฐ๋ณธ๊ฐ์ด 0์ด๋ฏ๋ก ์๋ฌด๋ฐ ํจ๊ณผ๊ฐ ๋ํ๋์ง ์๋๋ค. โ๏ธ
โ๏ธ all ํค์๋๋ฅผ ์ฐ๋ฉด ํด๋น ์์์ ๋ชจ๋ ๋ณ๊ฒฝ ๊ฐ๋ฅํ ์์ฑ์ ์๋์ผ๋ก ํจ๊ณผ๊ฐ ์ ์ฉ๋๋ค. โ๏ธ
โ๏ธ ๋ง์ฐ์ค ํธ๋ฒ(:hover)๋ฟ๋ง ์๋๋ผ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ํด๋์ค๋ฅผ ์ถ๊ฐ/์ ๊ฑฐํ ๋๋ transition์ ์๋ํ๋ค. โ๏ธ
โ๏ธ cursor: pointer; ์ ๊ฐ์ด ์ฌ์ฉํ๋ฉด ๊ฐ๋ ์ฑ์ด ์ข๋ค. โ๏ธ
๐ ์์ฑ๋ณ ์์ธ ์์ฝํ ๐
| ์ธ๋ถ ์์ฑ | ์ค๋ช | ์์ |
| property | ๋ณํ๋ฅผ ๊ฐ์ํ CSS ์์ฑ | opacity, width, all |
| duration | ์ ๋๋ฉ์ด์ ์ฌ์ ์๊ฐ | 0.3s, 500ms |
| timing-function | ์๋์ ํ๋ฆ (๊ฐ์๋) | linear, ease-in |
| delay | ์ค์ ์์๊น์ง ๊ธฐ๋ค๋ฆฌ๋ ์๊ฐ | 1s (1์ด ํ ์์) |
โ๏ธ ์ค์ ์์ ์ฝ๋ โ๏ธ
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Transition ํต์ฌ ์์ </title>
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
}
/* ๋ฒํผ */
.button {
width: 150px;
height: 50px;
background-color: #3498db;
color: white;
border: none;
cursor: pointer;
margin-bottom: 50px;
/* ๋ชจ๋ ์์ฑ์(all) 0.5์ด ๋์(0.5s) ๋ถ๋๋ฝ๊ฒ(ease-in-out) ๋ณํ */
transition: all 0.5s ease-in-out;
}
/* ๋ง์ฐ์ค๋ฅผ ์ฌ๋ ธ์ ๋์ ๋ณํ */
.button:hover {
background-color: #2ecc71;
width: 200px;
border-radius: 25px;
transform: scale(1.1);
}
.container {
border: 1px solid #ddd;
padding: 20px;
}
/* ๋ฐ์ค */
.box {
width: 150px;
height: 50px;
margin: 10px 0;
background-color: #3498db;
color: white;
display: flex;
align-items: center;
justify-content: center;
/* 2์ด ๋์ ์์น ์ด๋ */
transition: transform 2s;
}
/* hover ์ ์ด๋ */
.container:hover .box { transform: translateX(300px); }
/* ์ด์ง ์ฐจ์ด */
.linear { transition-timing-function: linear; }
.ease-in { transition-timing-function: ease-in; }
.ease-out { transition-timing-function: ease-out; }
</style>
</head>
<body>
<h2>๋ฒํผ ์ ๋๋ฉ์ด์
</h2>
<button class="button">Hover Me</button>
<h2>์ด์ง ํจ์ ๋น๊ต (๋ง์ฐ์ค ์ฌ๋ ค๋ณด์ธ์)</h2>
<div class="container">
<div class="box linear">Linear (์ผ์ ํ๊ฒ)</div>
<div class="box ease-in">Ease-In (๊ฐ์)</div>
<div class="box ease-out">Ease-Out (๊ฐ์)</div>
</div>
</body>
</html>
๐ cubic-bezier ( ์ฌ์ฉ์ ์ ์ ์๋ ๊ณก์ ) ๐
https://cubic-bezier.com/#.17,.67,.83,.67
cubic-bezier.com
cubic-bezier.com
Easing Functions Cheat Sheet
Easing functions specify the speed of animation to make the movement more natural. Real objects don’t just move at a constant speed, and do not start and stop in an instant. This page helps you choose the right easing function.
easings.net
https://matthewlein.com/tools/ceaser
Ceaser - CSS Easing Animation Tool - Matthew Lein
Choose an easing type and test it out with a few effects. If you don’t quite like the easing, grab a handle and fix it. When you’re happy, snag your code and off you go. Now that we can use CSS transitions in all the modern browsers, let’s make them
matthewlein.com
'<style>' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| perspective (0) | 2026.03.27 |
|---|---|
| CSS์ Animation๊ณผ @keyframes (0) | 2026.03.27 |
| Functions์ filter์์ฑ๊ณผ ํจ์ (0) | 2026.03.27 |
| transform ์์ฑ๊ณผ functions (ํจ์) (0) | 2026.03.26 |
| Pseudo-elements (์์ฌ ์์) (0) | 2026.03.26 |