CSS Transition & Transform & Animation
๐ก CSS์ Transition, Transform, Animation ์์ ์ ๋ฆฌ
๊ฐ์ ๐ซ
Interative ํ ์น ํ์ด์ง๋ฅผ ๋ง๋ค๊ธฐ ์ํ ๊ธฐ์ด์ธ CSS Transition, Animation์ ์ ๋ฆฌํด๋ณด์.
์ฌ์ฉ์์ ์ํธ์์ฉ์ ๋ฐ๋ผ ํ๋ คํ๊ฒ ์์ง์ด๋ ์น ์ฌ์ดํธ๋ฅผ ๋ง๋ค๊ธฐ ์ํด์๋ Javascript ์ง์์ด ์๋นํ ํ์ํ์ง๋ง, ๊ธฐ๋ณธ์ ์ผ๋ก Transition๊ณผ Animation์ ์๋ ๊ฒ๋ง์ผ๋ก๋ ์ด๋ ์ ๋ ๊ตฌํ์ด ๊ฐ๋ฅํ๋ค.
์ด๋ฒ ํฌ์คํธ์์๋ Transition๊ณผ Animation์ ์์ฑ๋ค์ ๋ค๋ค๋ณด๋๋ก ํ๊ฒ ๋ค.
ํ์ต ๋ด์ฉ ๐
Transition
CSS transitions๋ ์ฌ๋ฌ๋ถ์ด (๋ช ์์ ์ผ๋ก ๋ชฉ๋ก์ ์์ฑํด์) ์ด๋ค ์์ฑ์ ์์ง์ด๊ฒ ํ ์ง, (๋๋ ์ด๋ฅผ ์ค์ ํด์) ์ธ์ ์ ๋๋ฉ์ด์ ์ด ์์ํ ์ง, (์ง์ ์๊ฐ์ ์ค์ ํด์) ํธ๋์ง์ ์ ์ผ๋ง๋ ์ง์ํ ์ง, ๊ทธ๋ฆฌ๊ณ (์๋ฅผ ๋ค๋ฉด, ์ ํ์ด๊ฑฐ๋ ์ด๊ธฐ ๋น ๋ฆ, ์ข ๋ฃ ๋๋ฆผ๊ณผ ๊ฐ์ ํ์ด๋ฐ ํจ์๋ฅผ ์ ์ํด์) ์ด๋ป๊ฒ ํธ๋์ง์ ์ ์คํํ๋์ง ๊ฒฐ์ ํ๊ฒ ํฉ๋๋ค.
Transition์ ์์ฑ
- property
- duration
<style> .transition { transition-property: width; transition-duration: 2s; }</style>
.property
: ํจ๊ณผ๋ฅผ ์ ์ฉํ๊ณ ์ ํ๋ css ์์ฑ
.duration
: ํจ๊ณผ๊ฐ ๋ํ๋๋๋ฐ ๊ฑธ๋ฆฌ๋ ์๊ฐ
- timing-function
- delay
<style> .transition { transition-timing-function: linear; transition-delay: 1s; }</style>
.timing-function
: ํจ๊ณผ์ ์๋ (linear๋ โ์ผ์ ํ๊ฒโ๋ผ๋ ์๋ฏธ)
.delay
: ํน์ ์กฐ๊ฑด ํ์์ ํจ๊ณผ ๋ฐ๋ (1s๋ โ1์ด ํโ๋ผ๋ ์๋ฏธ)
- hover
<style> .transition:hover { width: 300px; }</style>
- css์์ ๋ฏธ๋ฆฌ ๋ง๋ค์ด ๋์ ํด๋์ค๋ก,ย ๋ง์ฐ์ค๋ฅผ ์ฌ๋ ธ์ ๋๋ผ๋ ์กฐ๊ฑด
- Note:ย **
.transition:hover
**๋ฅผ ๋์ด์ฐ๊ธฐ ์์ด ์์ฑํด์ผ ํจ
์ข ํฉ ์์
<style> .transition { transition: width 2s linear 1s; } .transition:hover { width: 300px; }</style>
- ๋ง์ฐ์ค๋ฅผ ์ฌ๋ฆฌ๋ฉดย 1์ด ํ์ width ๊ฐ์ดย 300px๋ก,ย 2์ด ๋์ ์๋ ์ผ์ ํ๊ฒ ๋ณํ๋ ์ ๋๋งค์ด์ ํจ๊ณผ ๋ฐ๋
Transform
CSS ์์ฑ์ ๋ณ๊ฒฝํ ๋ ์ ๋๋ฉ์ด์ ์๋๋ฅผ ์กฐ์ ํ ์ ์๊ฒ ํ๋ค.
CSS์ ์์ฑ ๋ณํ๊ฐ ์ง์ ํ ์ค์ ์๋ฐ๋ผ ์ผ์ด๋ ์ ์๊ฒ ๋ง๋ค์ด ์ค๋ค.
์์
<style> .transition { transfrom: rotate(45deg);/* ํ์ */transform: scale(2,3);/* ํ๋ ์ถ์ */ }</style>
.rotate(angle)
: ์ ๋ ฅํ ๊ฐ๋๋งํผ ํ์ ํ๋ฉฐ, ์์๋ ์ ๋ ฅ ๊ฐ๋ฅ.scale(x, y)
: ์ซ์๋ ๋น์จ์ ์๋ฏธํ๋ฉฐ width๋ฅผ x๋ฐฐ, height๋ฅผ y๋ฐฐ ๋งํผ ํ๋
Point IIskew, translate
<style> .transition { transform: skew(10deg, 20deg);/* ๊ฐ๋ ๋ณ๊ฒฝ */transform: translate(100px; 200px);/* ์์น ๋ณ๊ฒฝ */ }</style>
.skew(x, y)
: x์ถ, y์ถ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฅํ ๊ฐ๋๋งํผ ๋นํ.translate(x, y)
: ์ ํํ ์ค๋ธ์ ํธ์ ์ขํ ๋ณ๊ฒฝ
Point IIIprefix ์ ๋์ฌ
<style> .transition { -webkit-transform: translate(100px, 200px);/* ํฌ๋กฌ, ์ฌํ๋ฆฌ */ -mox-transform: translate(100px, 200px);/* ํ์ด์ดํญ์ค */ -ms-transform: translate(100px, 200px ;/* ์ต์คํ๋ก๋ฌ 9.0 */ -o-transform: translate(100px, 200px);/* ์คํ๋ผ */ }</style>
- Transform์ CSS์ ์ต์ ๋ฒ์ ์์๋ง ์คํ ๊ฐ๋ฅํ ํค์๋์ด์ง๋ง, prefix๋ฅผ ์ถ๊ฐํ๋ฉด ํ์ ๋ฒ์ ์ ๋ธ๋ผ์ฐ์ ์์๋ ์คํ ๊ฐ๋ฅ
Animation
CSS Selector์ ์ข ๋ฅ๋ฅผ ์์๋ณด๊ณ ์์ ๋ฅผ ํตํด ์ด๋ป๊ฒ ์ ์ฉ๋๋์ง ํ์ธํด๋ณด๊ฒ ๋ค.
์์
.animation { animation-name: changeWidth;/* ์ ๋๋งค์ด์
์ด๋ฆ */animation-duration: 3s; animation-timing-function: linear; animation-delay: 1s; animation-iteration-count: 6; animation-direction: alternate;}
@keyframes changeWidth { from { width: 300px; } to {width: 600px; ]}
.iteration-count
: ์ ๋๋ฉ์ด์ ๋ฐ๋ณต ํ์.direction
: ์ ๋๋งค์ด์ ์งํ ๋ฐฉํฅalternate
: from โ to โ fromnormal
: from โ to, from โ toreverse
: to โ from, to โ from
4. ์ ๋๋ฉ์ด์ ์์ฉ
Point ITransform & Animation
.box1 { animation: rotation 1500ms linear infinite alternate;}
@keyframes rotation { from { transform: rotate(-10deg); } to { transform: rotate(10deg); }}
- ์ ๋๋ฉ์ด์
์ฝ๋๋ฅผ ํ ์ค๋ก ์์ฑ์, ๋จผ์ ๋์ค๋ ์ซ์๊ฐย **
.duration
**์ด๊ณ , ๋์ค์ ๋์ค๋ ์ซ์๊ฐย.delay
Point IIprefix ์์ฑ์ ์ ์์ฌํญ
.box1 { -webkit-animation: rotation 3s linear 1s 6 alternate;}
@-webkit-keyframes rotation { from {-webkit-transform: rotate(-10deg); } to {-webkit-transform: rotate(10deg); }}
- prefix๊ฐ ๊ฐ์ ์ ๋๋ฉ์ด์ ๋ผ๋ฆฌ ์ฐ๋
Review ๐ก
CSS์ transition & transform & animation์ ์ ์ฌ์ฉํ๋ฉด ๋ง์ ๋ฐฉ์์ ์ด๋ฏธ์ง๋ UI๋ฅผ ๊ตฌํํ ์ ์์ ๊ฒ ๊ฐ๋ค.