๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

CSS ์†์„ฑ 13. transition-transform

โ—๏ธ ํ•ด๋‹น ๊ธ€์€ ํŒจ์ŠคํŠธ์บ ํผ์Šค - ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ ๊ฐ•์˜์—์„œ HTML & CSS, SASS(SCSS) Part์˜ ๋ฐ•์˜์›… ๊ฐ•์‚ฌ๋‹˜์˜ ๊ฐ•์˜์ž๋ฃŒ๋ฅผ ์ •๋ฆฌํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

transition#

CSS ์†์„ฑ์˜ ์‹œ์ž‘๊ณผ ๋์„ ์ง€์ •(์ „ํ™˜ ํšจ๊ณผ)ํ•˜์—ฌ ์ค‘๊ฐ„ ๊ฐ’์„ ์• ๋‹ˆ๋ฉ”์ด์…˜ - ๋‹จ์ถ• ์†์„ฑ


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
transition-property์ „ํ™˜ ํšจ๊ณผ๋ฅผ ์‚ฌ์šฉํ•  ์†์„ฑ ์ด๋ฆ„all
transition-duration์ „ํ™˜ ํšจ๊ณผ์˜ ์ง€์†์‹œ๊ฐ„ ์„ค์ •0s
transition-timing-functionํƒ€์ด๋ฐ ํ•จ์ˆ˜ ์ง€์ •ease
transition-delay์ „ํ™˜ ํšจ๊ณผ์˜ ๋Œ€๊ธฐ์‹œ๊ฐ„ ์„ค์ •0s

์˜ˆ์ œ#

<div class="box"></div>
.box {width: 100px;height: 100px;background: tomato;margin: 50px;transition: width 1s, background 2s;}.box:hover {width: 300px;background: dodgerblue;}

โ˜๏ธ transition ์ด ์ผ์–ด๋‚˜๊ธฐ ์ „ ๋‹จ๊ณ„์— ์†์„ฑ์„ ์ง€์ •ํ•œ๋‹ค.


transition-property#

์ „ํ™˜ ํšจ๊ณผ๋ฅผ ์‚ฌ์šฉํ•  ์†์„ฑ ์ด๋ฆ„์„ ์„ค์ • - ๊ฐœ๋ณ„ ์†์„ฑ


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
all๋ชจ๋“  ์†์„ฑ์— ์ ์šฉall
์†์„ฑ ์ด๋ฆ„์ „ํ™˜ ํšจ๊ณผ๋ฅผ ์‚ฌ์šฉํ•  ์†์„ฑ ์ด๋ฆ„

transition-duration#

์ „ํ™˜ ํšจ๊ณผ์˜ ์ง€์†์‹œ๊ฐ„์„ ์„ค์ • - ๊ฐœ๋ณ„ ์†์„ฑ


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
์‹œ๊ฐ„์ „ํ™˜ ํšจ๊ณผ๊ฐ€ ์ง€์†๋˜๋Š” ์‹œ๊ฐ„0s

โ˜๏ธ ms ๋‹จ์œ„๋„ ๊ฐ€๋Šฅ


transition-timing-function#

ํƒ€์ด๋ฐ ํ•จ์ˆ˜(์• ๋‹ˆ๋ฉ”์ด์…˜ ์ „ํ™˜ ํšจ๊ณผ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ๋ฒ•) ์ง€์ • - ๊ฐœ๋ณ„ ์†์„ฑ


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’Cubic Bezier ๊ฐ’
ease๋น ๋ฅด๊ฒŒ - ๋Š๋ฆฌ๊ฒŒeasecubic-bezier(.25, .1, .25, 1)
linear์ผ์ •ํ•˜๊ฒŒcubic-bezier(0, 0, 1, 1)
ease-in๋Š๋ฆฌ๊ฒŒ - ๋น ๋ฅด๊ฒŒcubic-bezier(.42, 0, 1, 1)
ease-out๋น ๋ฅด๊ฒŒ - ๋Š๋ฆฌ๊ฒŒcubic-bezier(0, 0, .58, 1)
ease-in-out๋Š๋ฆฌ๊ฒŒ - ๋น ๋ฅด๊ฒŒ - ๋Š๋ฆฌ๊ฒŒcubic-bezier(.42, 0, .58, 1)
cubic-bezier(n, n, n, n)์ž์‹ ๋งŒ์˜ ๊ฐ’์„ ์ •์˜ ( 0 ~ 1 )
steps(n)n ๋ฒˆ ๋ถ„ํ• ๋œ ์• ๋‹ˆ๋ฉ”์ด์…˜

Easing Functions Cheat Sheet


transition-delay#

์ „ํ™˜ ํšจ๊ณผ๊ฐ€ ๋ช‡ ์ดˆ ๋’ค์— ์‹œ์ž‘ํ• ์ง€ ๋Œ€๊ธฐ์‹œ๊ฐ„์„ ์„ค์ • - ๊ฐœ๋ณ„ ์†์„ฑ


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
์‹œ๊ฐ„์ „ํ™˜ ํšจ๊ณผ์˜ ๋Œ€๊ธฐ์‹œ๊ฐ„์„ ์„ค์ •0s

โ˜๏ธ transition: 2s 3s; ๋กœ ์ž…๋ ฅํ•˜๋ฉด ์•ž์— ์˜ค๋Š” ์‹œ๊ฐ„์ด duration , ๋’ค์— ์˜ค๋Š” ์‹œ๊ฐ„์ด delay ์ด๋‹ค.


transform#

์š”์†Œ์˜ ๋ณ€ํ™˜ ํšจ๊ณผ(๋ณ€ํ˜•)์„ ์ง€์ • - ๋‹จ์ถ• ์†์„ฑ


transform 2D ๋ณ€ํ™˜ ํ•จ์ˆ˜#

๊ฐ’(๋ณ€ํ™˜ํ•จ์ˆ˜)์˜๋ฏธ๋‹จ์œ„
translate(x, y)์ด๋™(X์ถ•, Y์ถ•)๋‹จ์œ„
translate(x)์ด๋™(X์ถ•)๋‹จ์œ„
translate(y)์ด๋™(Y์ถ•)๋‹จ์œ„
scale(x, y)ํฌ๊ธฐ(X์ถ•, Y์ถ•)์—†์Œ(๋ฐฐ์ˆ˜)
scaleX(x)ํฌ๊ธฐ(X์ถ•)์—†์Œ(๋ฐฐ์ˆ˜)
scaleY(y)ํฌ๊ธฐ(Y์ถ•)์—†์Œ(๋ฐฐ์ˆ˜)
rotate(degree)ํšŒ์ „(๊ฐ๋„)deg
skew(x-deg, y-deg)๊ธฐ์šธ์ž„(X์ถ•, Y์ถ•)deg
skewX(x-deg)๊ธฐ์šธ์ž„(X์ถ•)deg
skewY(y-deg)๊ธฐ์šธ์ž„(Y์ถ•)deg
matrix(n, n, n, n, n, n)2์ฐจ์› ๋ณ€ํ™˜ ํšจ๊ณผ์—†์Œ

transform 3D ๋ณ€ํ™˜ ํ•จ์ˆ˜#

๊ฐ’(๋ณ€ํ™˜ํ•จ์ˆ˜)์˜๋ฏธ๋‹จ์œ„
translate3d(x, y, z)์ด๋™(X์ถ•, Y์ถ•, Z์ถ•)๋‹จ์œ„
translateZ(z)์ด๋™(Z์ถ•)๋‹จ์œ„
scale3d(x, y, z)ํฌ๊ธฐ(X์ถ•, Y์ถ•, Z์ถ•)์—†์Œ(๋ฐฐ์ˆ˜)
scaleZ(z)ํฌ๊ธฐ(Z์ถ•)์—†์Œ(๋ฐฐ์ˆ˜)
rotate3d(x, y, z, a)ํšŒ์ „(X๋ฒกํ„ฐ, Y๋ฒกํ„ฐ, Z๋ฒกํ„ฐ, ๊ฐ๋„)์—†์Œ, deg
rotateX(x)ํšŒ์ „(X์ถ•)deg
rotateY(y)ํšŒ์ „(Y์ถ•)deg
rotateZ(z)ํšŒ์ „(Z์ถ•)deg
perspective(n)์›๊ทผ๋ฒ•(๊ฑฐ๋ฆฌ)๋‹จ์œ„
matrix3d(n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n)3์ฐจ์› ๋ณ€ํ™˜ ํšจ๊ณผ์—†์Œ

์‚ฌ์šฉ๋ฒ•#

transform: ๋ณ€ํ™˜ํ•จ์ˆ˜1 ๋ณ€ํ™˜ํ•จ์ˆ˜2 ๋ณ€ํ™˜ํ•จ์ˆ˜3 ...;transform: ์›๊ทผ๋ฒ• ์ด๋™ ํฌ๊ธฐ ํšŒ์ „ ๊ธฐ์šธ์ž„;
.box {transform: rotate(20deg) translate(10px, 0);}

2D ๋ณ€ํ˜• ํšจ๊ณผ, 3D ๋ณ€ํ˜• ํšจ๊ณผ๊ฐ€ ์žˆ๋‹ค.


2D ์˜ˆ์ œ#

<div class="box">123</div>
.box {width: 200px;height: 200px;background: tomato;display: flex;justify-content: center;align-items: center;font-size: 30px;transition: 1s;}.box:hover {transform: translate(30px, 30px);}

โ˜๏ธ translate(30px, 30px) vs position: relative; left: 30px; top: 30px; : position ์€ ์–ด๋Š ์œ„์น˜์— ๋ฐฐ์น˜ํ•ด๋†“๊ณ  ์œ„์น˜๊ฐ€ ๋‹ค์‹œ ๋ณ€ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๊ณ  (์• ๋‹ˆ๋ฉ”์ด์…˜์— ์ตœ์ ํ™”๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.) translate ๋Š” ์œ„์น˜๊ฐ€ ์ˆ˜์‹œ๋กœ ๋ณ€ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•œ๋‹ค.


3D ์˜ˆ์ œ#

<img src="https://heropy.blog/css/images/logo.png" alt="HEROPY">
img {width: 300px;border: 1px solid lightgray;transform: perspective(500px) rotateX(45deg);}

โ˜๏ธ perspective() ๋Š” transform์˜ ์†์„ฑ ๊ฐ’ ์ค‘์— ์ œ์ผ ์•ž์— ์™€์•ผ ํ•œ๋‹ค.


transform ๋ณ€ํ™˜ ์†์„ฑ#

์†์„ฑ์˜๋ฏธ
transform-origin์š”์†Œ ๋ณ€ํ™˜์˜ ๊ธฐ์ค€์ ์„ ์„ค์ •
transform-style3D ๋ณ€ํ™˜ ์š”์†Œ์˜ ์ž์‹ ์š”์†Œ๋„ 3D ๋ณ€ํ™˜์„ ์‚ฌ์šฉํ• ์ง€ ์„ค์ •
perspectiveํ•˜์œ„ ์š”์†Œ๋ฅผ ๊ด€์ฐฐํ•˜๋Š” ์›๊ทผ ๊ฑฐ๋ฆฌ๋ฅผ ์„ค์ •
perspective-origin์›๊ทผ ๊ฑฐ๋ฆฌ์˜ ๊ธฐ์ค€์ ์„ ์„ค์ •
backface-visibility3D ๋ณ€ํ™˜์œผ๋กœ ํšŒ์ „๋œ ์š”์†Œ์˜ ๋’ท๋ฉด ์ˆจ๊น€์„ ์„ค์ •

transform-origin#

์š”์†Œ ๋ณ€ํ™˜์˜ ๊ธฐ์ค€์ ์„ ์„ค์ •


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
X์ถ•left , right , center , % , ๋‹จ์œ„50%
Y์ถ•top , bottom , center , % , ๋‹จ์œ„50%
Z์ถ•๋‹จ์œ„0

์˜ˆ์ œ#

<img src="https://heropy.blog/css/images/logo.png" alt="HEROPY">
img {width: 200px;border: 1px solid lightgray;transition: 1s;transform: rotate(45deg);transform-origin: 100% 100%;}

transform-style#

3D ๋ณ€ํ™˜ ์š”์†Œ์˜ ์ž์‹ ์š”์†Œ๋„ 3D ๋ณ€ํ™˜์„ ์‚ฌ์šฉํ• ์ง€ ์„ค์ •


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
flat์ž์‹ ์š”์†Œ์˜ 3D ๋ณ€ํ™˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œflat
preserve-3d์ž์‹ ์š”์†Œ์˜ 3D ๋ณ€ํ™˜์„ ์‚ฌ์šฉํ•จ

์˜ˆ์ œ#

<div class="perspective"><div class="grand-parent"><div class="parent"><img src="https://heropy.blog/css/images/logo.png" alt="HEROPY"></div></div></div>
.perspective {width: 200px;perspective: 500px;padding: 70px;}.grand-parent{width: 200px;border: 3px solid dodgerblue;transition: 1s;transform: rotateX(-45deg);transform-style: preserve-3d;}.parent {width: 200px;border: 3px solid tomato;transition: 1s;transform: rotateY(45deg);transform-style: preserve-3d;}img {width: 200px;border: 3px solid lightgray;transition: 1s;transform: rotateX(45deg);}

perspective#

ํ•˜์œ„ ์š”์†Œ๋ฅผ ๊ด€์ฐฐํ•˜๋Š” ์›๊ทผ ๊ฑฐ๋ฆฌ๋ฅผ ์„ค์ •


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
๋‹จ์œ„px , em , cm ๋“ฑ ๋‹จ์œ„๋กœ ์ง€์ •

perspective ์†์„ฑ๊ณผ ํ•จ์ˆ˜์˜ ์ฐจ์ด์ #

์†์„ฑ/ํ•จ์ˆ˜์ ์šฉ๋Œ€์ƒ๊ธฐ์ค€์  ์„ค์ •
perspective๊ด€์ฐฐ ๋Œ€์ƒ์˜ ๋ถ€๋ชจ ์š”์†Œperspective-origin
transform: perspective()๊ด€์ฐฐ ๋Œ€์ƒtransform-origin

perspective-origin#

์›๊ทผ ๊ฑฐ๋ฆฌ์˜ ๊ธฐ์ค€์ ์„ ์„ค์ •


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
X์ถ•left , right, center, % , ๋‹จ์œ„0.5
Y์ถ•top , bottom , center , % , ๋‹จ์œ„0.5

backface-visibility#

3D ๋ณ€ํ™˜์œผ๋กœ ํšŒ์ „๋œ ์š”์†Œ์˜ ๋’ท๋ฉด ์ˆจ๊น€์„ ์„ค์ •


์†์„ฑ ๊ฐ’#

๊ฐ’์˜๋ฏธ๊ธฐ๋ณธ๊ฐ’
visible๋’ท๋ฉด ์ˆจ๊ธฐ์ง€ ์•Š์Œvisible
hidden๋’ท๋ฉด ์ˆจ๊น€

matric(a, b, c, d, e, f)#

์š”์†Œ์˜ 2์ฐจ์› ๋ณ€ํ™˜(Transforms) ํšจ๊ณผ๋ฅผ ์ง€์ •

2020-02-03-css-์†์„ฑ-13-transition-transform-image-0

scale() , skew() , translate() , rotate() ๋ฅผ ์ง€์ •

matrix-function

โ˜๏ธ ์š”์†Œ์˜ ์ผ๋ฐ˜ ๋ณ€ํ™˜(Transforms) ํ•จ์ˆ˜(2D, 3D)๋ฅผ ์‚ฌ์šฉํ•˜๋”๋ผ๋„ ๋ธŒ๋ผ์šฐ์ €์— ์˜ํ•ด matrix ํ•จ์ˆ˜๋กœ ๊ณ„์‚ฐ๋˜์–ด ์ ์šฉ๋œ๋‹ค. (2D ๋ณ€ํ™˜ ํ•จ์ˆ˜๋Š” matrix ๋กœ, 3D ๋ณ€ํ™˜ ํ•จ์ˆ˜๋Š” matrix3d ๋กœ) ๋”ฐ๋ผ์„œ ์ผ๋ฐ˜์ ์ธ ๊ฒฝ์šฐ๋Š” matrix ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ผ๋ฐ˜ ๋ณ€ํ™˜ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.


Reference#

ํŒจ์ŠคํŠธ์บ ํผ์Šค - ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ ๊ฐ•์˜ - HTML & CSS, SASS(SCSS) Part by ParkYoungWoong