๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
CSS

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ : GIF ์ด๋ฏธ์ง€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ตฌํ˜„ํ•˜๊ธฐ

by ์ฝ”ํŒŒ์นด 2022. 9. 8.
728x90

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ : GIF ์ด๋ฏธ์ง€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ตฌํ˜„ํ•˜๊ธฐ

์˜ค๋Š˜์€ ์กฐ๊ธˆ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ, GIF ์ด๋ฏธ์ง€๋ฅผ ์• ๋‹ˆ๋ฉ”์ด์…˜์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


1. ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค ์ด๋ฏธ์ง€ ์ฐพ๊ธฐ

๋จผ์ €, ์–ด๋– ํ•œ GIF ์ด๋ฏธ์ง€๋ฅผ ์• ๋‹ˆ๋ฉ”์ด์…˜์œผ๋กœ ๋งŒ๋“ค ๊ฒƒ์ธ์ง€ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

2. ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ํ”„๋ ˆ์ž„ ๋‚˜์—ดํ•˜๊ธฐ

Photoshop์—์„œ GIF ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ ธ์™€ Timeline ์ฐฝ์„ ๋„์šฐ๋ฉด, GIF๋ฅผ ์ด๋ฃจ๊ณ  ์žˆ๋Š” ๊ฐ๊ฐ์˜ ๋ ˆ์ด์–ด๋“ค์ด ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ์—ฌ์šฐ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ๋Š” 1600px * 1200px์ด๋ฉฐ, ๋ ˆ์ด์–ด๋Š” ์ด 18๊ฐœ๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. GIF์˜ ์ด๋ฏธ์ง€์˜ ๋„ˆ๋น„(1600px) X ๋ ˆ์ด์–ด ์ˆ˜(18)์˜ ๊ฐ’(28,800px)์„ ๊ตฌํ•ด์ค๋‹ˆ๋‹ค. ์ดํ›„, width๊ฐ’์ด 28,800px, height๊ฐ’์ด 1200px์ธ ์ƒˆ๋กœ์šด ์ฐฝ์„ ๋งŒ๋“ค๊ณ , ์—ฌ์šฐ์˜ ์›€์ง์ž„์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ๊ฐ์˜ ๋ ˆ์ด์–ด๋“ค์„ ๊ฐ€๋กœ๋กœ ๋‚˜์—ดํ•œ ๋’ค ์ด๋ฏธ์ง€๋กœ ์ €์žฅํ•ด ์ค๋‹ˆ๋‹ค.

3. ์ฝ”๋”ฉ

์ด๋ฏธ์ง€๊ฐ€ ์ค€๋น„๋˜์—ˆ๋‹ค๋ฉด, ์ด์ œ ์ฝ”๋”ฉ์„ ํ•ด๋ด…์‹œ๋‹ค. ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋กœ steps๋ฅผ ์‹œ์ž‘์ ์—์„œ ๋ ˆ์ด์–ด ์ˆ˜๋งŒํผ ์„ค์ •ํ•ด ์ฃผ๊ณ , keyframes๋กœ ์ด๋ฏธ์ง€์˜ background-position์— ๋ณ€ํ™”๋ฅผ ์ฃผ๋ฉด ์™„์„ฑ์ž…๋‹ˆ๋‹ค.

.step {
    height: 800px;
    background: #ffe8d9;
    position: relative;
    overflow: hidden;
}
.step .stepbox {
    width: 1600px;
    height: 1200px;
    background: url(img/ani1.jpg);
    border-radius: 0;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    animation: ani 0.7s steps(18, start) infinite;
}
.step .stepbox.start {
    animation-play-state: running;
}
.step .stepbox.stop {
    animation-play-state: paused;
}
@keyframes ani {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: -28800px 0;
    }
}
.stepBtn {
    position: absolute;
    left: 15px;
    top: 20px;
}
.stepBtn a {
    background: #e16162;
    color: #fff;
    padding: 10px;
    margin: 3px;
    border-radius: 3px;
}

4. ๊ฒฐ๊ณผ ํ™•์ธํ•˜๊ธฐ

See the Pen foxanimation by mj0614k (@mj0614k) on CodePen.

728x90

๋Œ“๊ธ€

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๐Ÿฆ™

CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘