[CSS] Animation / imageSprites

Chenยท2024๋…„ 6์›” 4์ผ
0

CSS

๋ชฉ๋ก ๋ณด๊ธฐ
4/8
post-thumbnail
  • Transition๊ณผ Animation์˜ ๊ฐ€์žฅ ํฐ ์ฐจ์ด์  = keyframe ์œ ๋ฌด

timing-function

  • Animation์€ Transtion์™€ ๊ฐ™์ด timing-func์€ ease๊ฐ€ default
@keyframes sample-ani {
    0% {
        transform: translate(0, 0);
    }
    50% {
        transform: translate(500px, 0);
        background-color: red;
    }
    100% {

        transform: translate(600px, 200px); 
    }
}
.box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
    border: 2px solid #000;
    background-color: #fff000;
    animation: sample-ani 2s ease infinite;
}

animation-direction

animation-direction : alternate, reverse

alternate-reverse๋„ ๊ฐ€๋Šฅ! reverse๋œ ์ƒํƒœ๋กœ alternate

animation: sample-ani 3s ease infinite alternate;

animation-fill-mode

๊ธฐ๋ณธ๊ฐ’์€ none
forwards = ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ข…๋ฃŒ ์ง€์  100%์— ๋‘๊ธฐ


animation-play-state

๊ธฐ๋ณธ๊ฐ’์€ running
์• ๋‹ˆ๋ฉ”์ด์…˜ paused or not

.box:hover {
    animation-play-state: paused;
}

์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ ๊ธฐ๋ฒ• (frame-by-frame)

  • ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ w - 5100px, h : 150px
.spaceship {
    width: 150px;
    height: 150px;
    background: url('../images/sprite_spaceship.png') no-repeat 0 0 / auto 150px;
    /* 5100px 300px */
    /* ์ง€๊ธˆ์˜ ๊ฒฝ์šฐ, cover ๊ฐ€๋Šฅ */
    animation: spaceship-ani s infinite steps(17) reverse;
}

background

background-size๋Š” /๋กœ ๊ตฌ๋ถ„ํ•ด์ฃผ๋ฉด ๋œ๋‹ค =>

background: url('image.png') no-repeat 0 0 / auto 150px; }

์ด๋ฏธ์ง€ ์ž๋™์œผ๋กœ ๋น„์œจ ๋งž์ถฐ์ฃผ๊ธฐ (๋‚˜๋ˆ„๊ธฐ ์‰ฌ์šด๊ฑฐ ํ•˜๋‚˜๋งŒ 2๋กœ ๋‚˜๋ˆ„๊ณ  => auto )
auto 150px


steps( n ๋ฒˆ )

  • animation ์†์„ฑ ์ค‘ ํ•˜๋‚˜

@keyframes

  • ์ดˆ๊ธฐ CSS ์„ธํŒ…๊ณผ ๋ณ€ํ™”๊ฐ€ ์—†์„์‹œ 0% ์•ˆ์ ์–ด์ค˜๋„ ๋จ
@keyframes spaceship-ani {
    to { /* from ~ to, 0% ~ 100%*/
        background-position: -2550px 0;
    }
}
  • -2550px 0 ์ธ ์ด์œ  = left ๋ฐฉํ–ฅ์œผ๋กœ ํ˜๋Ÿฌ๊ฐ€๋“ฏ์ด ์ด๋™
  • 5100px์ด ์•„๋‹Œ ์ด์œ  = bg-size๋ฅผ ์ฒ˜์Œ์— auto 150px๋กœ ๋ฐ˜๋ต ๋น„์œจ๋กœ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ

gif ๋‘๊ณ  ์™œ frameByFrame?

  • gif๋Š” ์•ŒํŒŒ ์ฑ„๋„(Alpha Channel), ์ฆ‰ ํˆฌ๋ช…๋„๊ฐ€ ์ ์šฉ์ด ์•ˆ๋œ๋‹ค๋Š” ์น˜๋ช…์  ๋‹จ์ ์ด ์žˆ์Œ

  • ๋„ํŠธ ์ฐ์–ด์„œ ํ‘œํ˜„ํ•œ ํ”ฝ์…€ ์•„ํŠธ๊ฐ€ ์•„๋‹Œ ์ด์ƒ, ์ด๋ฏธ์ง€ ๊ฐ€์žฅ์ž๋ฆฌ๊ฐ€ ๊นจ์ง„ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ž„ (์•ˆํ‹ฐ ์•จ๋ฆฌ์–ด์‹ฑ โŒ)

  • cf. ๋ฐ˜๋ฉด, png๋Š” ์•ŒํŒŒ์ฑ„๋„์ด ์ ์šฉ๋˜๋Š” ์ด๋ฏธ์ง€ (apng๋„ ์žˆ์ง€๋งŒ ์ง€์› ์•ˆํ•˜๋Š” ๋ธŒ๋ผ์šฐ์ € ๋งŽ์Œ)

์•ŒํŒŒ ์ฑ„๋„(Alpha Channel) = ์•ŒํŒŒ์ฑ„๋„(Alpha Channel)์€ RGB์ฑ„๋„์— ์ €์žฅ๋˜๋Š” RGB๊ฐ’ ์ด์™ธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ฑ„๋„

์•ˆํ‹ฐ ์•จ๋ฆฌ์–ด์‹ฑ(Anti-Aliasing) = ๋†’์€ ํ•ด์ƒ๋„์˜ ์‹ ํ˜ธ๋ฅผ ๋‚ฎ์€ ํ•ด์ƒ๋„์—์„œ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์ƒ๊ธฐ๋Š” ๊ณ„๋‹จ ํ˜„์ƒ(๊นจ์ง„ ํŒจํ„ด)์„ ์ตœ์†Œํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ• (์ถœ์ฒ˜ : ์œ„ํ‚ค๋ฐฑ๊ณผ)

  • ๋˜ ๋‹ค๋ฅธ ์žฅ์  : reverse, duration ๋“ฑ ๋งˆ์Œ๋Œ€๋กœ ์กฐ์ • ๊ฐ€๋Šฅ
profile
ํ˜„์‹ค์ ์ธ ๋ชฝ์ƒ๊ฐ€

0๊ฐœ์˜ ๋Œ“๊ธ€