Notice
Recent Posts
Recent Comments
Link
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[CSS] Transform, Transition, Animation์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž ๋ณธ๋ฌธ

๐Ÿง‘‍๐Ÿ’ป Web/CSS

[CSS] Transform, Transition, Animation์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž

Lennon 2022. 4. 7. 02:52
728x90
๋ฐ˜์‘ํ˜•

1. Transform

 

transform์€ ์–ด๋–ค ์š”์†Œ์— ๋Œ€ํ•ด  ํšŒ์ „, ํฌ๊ธฐ ๋ณ€๊ฒฝ ๋“ฑ์˜ ๋™์ž‘์„ ํ•˜๋„๋ก ํ•˜๋Š” CSS ์ด๋ฒคํŠธ์ด๋‹ค.

 

์ข…๋ฅ˜๋Š” rotate(ํšŒ์ „), scale(ํฌ๊ธฐ), skew(x์ถ•,y์ถ• ๊ฐ๋„๋งŒํผ ๋น„ํ‹‚), translate(์ขŒํ‘œ ๋ณ€๊ฒฝ)์ด ์žˆ๋‹ค.

 

1. rotate(x)

์ธ์ž๋กœ ํšŒ์ „ํ•  ๊ฐ๋„๋ฅผ ์ฃผ๋ฉด ๋œ๋‹ค. deg๋ผ๋Š” ๋‹จ์œ„๋ฅผ ์‚ฌ์šฉํ•˜์ž.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

2. scale(width,height)

์ธ์ž๋ฅผ ๋‘ ๊ฐœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. ๊ฐ๊ฐ width, height๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

1์ด ์›๋ž˜ ํฌ๊ธฐ์ด๋ฉฐ, 1 ์ดˆ๊ณผ์ผ์ˆ˜๋ก ๋ณธ๋ž˜์˜ ํฌ๊ธฐ๋ณด๋‹ค ์ปค์ง€๋ฉฐ, ๋ฏธ๋งŒ์ด๋ฉด ์ž‘์•„์ง„๋‹ค.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

3. skew(x์ถ•, y์ถ•)

์ธ์ž๋ฅผ ๋‘ ๊ฐœ ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, x์ถ•, y์ถ•์„ ์˜๋ฏธํ•˜๋ฉฐ, ์ž…๋ ฅํ•œ ๋งŒํผ ๋น„ํ‹€์–ด์ง„๋‹ค.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

4. translate(๊ฐ€๋กœ, ์„ธ๋กœ)

์ธ์ž๋ฅผ ๋‘ ๊ฐœ ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๊ฐ€๋กœ, ์„ธ๋กœ๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ, ์›๋ž˜ ์œ„์น˜์—์„œ ์ž…๋ ฅํ•œ ๊ฐ’๋งŒํผ ์ด๋™ํ•œ๋‹ค.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

2. Transition

๋ฐ”๋กœ ์ด๋ฒคํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒŒ ์•„๋‹Œ, ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ–ˆ์„ ๋•Œ, ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ ค๋†จ์„ ๋•Œ ๋“ฑ

์–ด๋–ค ์š”์†Œ์— ์ด๋ฒคํŠธ๊ฐ€ ๋™์ž‘ํ•˜๋ฉด ์‹คํ–‰๋˜๋Š” ์ด๋ฒคํŠธ์ด๋‹ค.

 

Transition๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•œ๋‹ค.

.box {
  transition-property: width;
  /* ํšจ๊ณผ๋ฅผ ์ ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” css์†์„ฑ */
  transition-duration: 2s;
  /* ํšจ๊ณผ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ */
  transition-timing-function: linear;
  /* ํšจ๊ณผ์˜ ์†๋„, linear๋Š” ์ผ์ •ํ•œ ์†๋„์ด๋ฉฐ ์ฃผ๋กœ ์ด๊ฑธ ์‚ฌ์šฉํ•œ๋‹ค.*/
  transition-delay: 1s;
  /* ํŠน์ • ์กฐ๊ฑด์„ ๊ฑธ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๊ทธ์— ๋”ฐ๋ผ ๋ฐœ๋™๋œ๋‹ค. 1s๋Š” 1์ดˆ ํ›„ ๋ฐœ๋™๋œ๋‹ค. */
}

Shorthand ๋ฌธ๋ฒ•์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด  ํ•œ ๋ฒˆ์— ๋‚˜์—ดํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

์œ„ ์ฝ”๋“œ์™€ ์•„๋ž˜ ์ฝ”๋“œ๋Š” ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

.box {
  transition: width 2s linear 1s;
}

๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ฆฌ๋ฉด ๋ฐ•์Šค์˜ width๊ฐ€ ์ ์  ๊ธธ์–ด์ง€๋Š” ๊ฑธ ๋งŒ๋“ค์–ด๋ณด์ž!

์œ„์— ๋งํ–ˆ๋‹ค์‹œํ”ผ ํŠน์ • ์ด๋ฒคํŠธ๊ฐ€ ์žˆ์„ ๋•Œ ๋™์ž‘ํ•˜๋ฏ€๋กœ hover์„ ๋“ฑ๋กํ•ด์คฌ๋‹ค.

๐Ÿ”ฅ ๋˜ํ•œ, delay๋Š” ํ•„์š”ํ•  ๋•Œ๋งŒ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค! linear๋Š” ์‚ฌ์šฉํ•ด์ค˜์•ผ ๋™์ผํ•œ ์†๋„๋กœ ์ผ์ •ํ•˜๊ฒŒ ๋™์ž‘ํ•˜๋‹ˆ ์‚ฌ์šฉํ•ด์ฃผ์ž.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

3. Animation

ํŠน์ • ์ด๋ฒคํŠธ ์—†์ด ์ฐฝ์ด ์—ด๋ ธ์„ ๋•Œ ๋‚˜์˜ค๋Š” animation ๋Š๋‚Œ์ด๋ผ ์ƒ๊ฐํ•˜๋ฉด ํŽธํ•˜๋‹ค.

animation์˜ ๊ธฐ๋ณธ์ ์ธ ๋™์ž‘์„ ํ™•์ธํ•˜๊ณ , animation-direction์˜ ๊ฐ๊ฐ ์†์„ฑ์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€ ํ™•์ธํ•˜์ž.

 

@keyframes๋Š” from๊ณผ to ์ธ์ž๋ฅผ ๊ฐ€์ง€๋ฉฐ, from => to๋กœ ๋™์ž‘ํ•œ๋‹ค๊ณ  ์ดํ•ดํ•˜๋ฉด ํŽธํ•˜๋‹ค.

์•„๋ž˜์˜ chageColor์™€ ๊ฐ™์ด 

animation-name๊ณผ @keyframes animation name์ด ์ผ์น˜ํ•ด์•ผ ๋™์ž‘ํ•œ๋‹ค.

.box {

    animation-name: changeColor;
    animation-duration: 3s;
    animation-timing-function: linear;
    animation-delay: 1s;
    /* transition์˜ ํŠน์„ฑ๊ณผ ๊ฐ™๋‹ค. */
    
    animation-iteration-count: infinite;
    /* animation ์ง€์† ํšŸ์ˆ˜๋ฅผ ์ง€์ •ํ•œ๋‹ค. infinite๋Š” ๋ฌดํ•œ์ด๋‹ค. */
    animation-direction: alternate;
    /* alternate = from => to => from
       normal = from => to, form => to
       reverse: to => from, to => from
    */
}

@keyframes changeColor {
    from {
       background-color: blue;
    }
    to {
       background-color: red;
    }
}

๋‹น์—ฐํžˆ animation๋„ Shorthand๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

.box {
	animation: changeColor 3s linear infinite alternate;
}

@keyframes changeColor {
    from {
       background-color: blue;
    }
    to {
       background-color: red;
    }
}

๊ฐ„๋‹จํ•˜๊ฒŒ ํ™•์ธํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋™์ž‘ํ•œ๋‹ค.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

alternate, normal, reverse ๋™์ž‘ ์ฐจ์ด๋Š” ํ•ด๋‹น codepen์œผ๋กœ ์‹œ๊ฐ์ ์œผ๋กœ ํ™•์ธํ•ด๋ณด์ž.

๊ฐ€์žฅ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์€ alternate์ด๋‹ค.

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

 

4. Transform๊ณผ Animation์„ ๊ฐ™์ด ์‚ฌ์šฉํ•ด๋ณด์ž.

@keyframes from, to์ธ์ž์— transform์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

 

4-1. ์˜ค๋š์ด ๋งŒ๋“ค๊ธฐ

See the Pen Untitled by PARKMINHO (@pmhxhsj) on CodePen.

@keyframes rotation {
  from {
    transform: rotate(-30deg);
  }
  to {
    transform: rotate(30deg);
  }
}

@keyframes์— transform์„ ์ ์šฉํ•ด ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค!

 

5. prefix

css์˜ ์–ด๋– ํ•œ ๊ธฐ๋Šฅ์ด ํŠน์ • ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ ‘๋‘์‚ฌ(prefix)๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ๋ธŒ๋ผ์šฐ์ €์— ๊ธฐ๋Šฅ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๋ฉฐ 

๋™์ž‘๋  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 

์•„๋ž˜์™€ ๊ฐ™์ด 4์ข…๋ฅ˜์˜ prefix๋ฅผ ๊ธฐ์–ตํ•˜์ž.

.box {
  -webkit-transform: scale(2); /* ํฌ๋กฌ, ์‚ฌํŒŒ๋ฆฌ */
  -moz-transform: scale(2); /* ํŒŒ์ด์–ดํญ์Šค */
  -ms-transform: scale(2); /* ์ต์Šคํ”Œ๋กœ๋Ÿฌ 9.0 ์ด์ƒ */
  -o-transform: scale(2); /* ์˜คํŽ˜๋ผ */
}

๊ทธ๋ฆฌ๊ณ  ์œ„์˜ ์˜ค๋š์ด ์˜ˆ์‹œ์— webkit์„ ์ ์šฉํ•ด๋ณด์ž.

.box {
  width: 100px;
  height: 100px;
  background-color: red;
  border-radius: 20% 20% 50% 50%; 
  
  -webkit-animation: rotation 1s linear infinite alternate;
}

@-webkit-keyframes rotation {
  from {
    -webkit-transform: rotate(-30deg);
  }
  to {
    -webkit-transform: rotate(30deg);
  }
}

animation, keyframes, transform ๋ชจ๋‘์— -webkit-์„ ๋ถ™์—ฌ์•ผ ์ ์šฉ๋œ ๊ฒƒ์ด๋‹ค. ๋งŒ์•ฝ ํ•˜๋‚˜๋ผ๋„ ๋น ๋œจ๋ฆฌ๋ฉด ์–ด๋– ํ•œ ์š”์†Œ์— ๋Œ€ํ•œ 

ํฌ๋กœ์Šค ๋ธŒ๋ผ์šฐ์ง•์ด ์ด๋ฃจ์–ด์ง€์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค.

 

 

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ transform, transition, animation์— ๋Œ€ํ•ด ์•Œ์•„๋ดค๋‹ค. 

๋‹ค ์™ธ์šธ ํ•„์š”๋Š” ์—†๊ณ  ํŠน์ • ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•  ๋•Œ ์ฐพ์•„์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ์ •๋„์˜ ๊ฐœ๋…๋งŒ ํ•™์Šตํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค!

728x90
๋ฐ˜์‘ํ˜•

'๐Ÿง‘โ€๐Ÿ’ป Web > CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[CSS3] ์…€๋ ‰ํ„ฐ(Selector)  (0) 2022.01.26
Comments