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

๊ฑธ์–ด๊ฐ€์ž

by oranssy 2022. 9. 8.
728x90
๋ฐ˜์‘ํ˜•

โญ๏ธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ : ๊ฑธ์–ด๊ฐ€์ž โญ๏ธ


01. ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ

์• ๋‹ˆ๋ฉ”์ด์…˜(Animation) ํšจ๊ณผ๋Š” HTML ์š”์†Œ์— ์ ์šฉ๋˜๋Š” CSS ์Šคํƒ€์ผ์„ ๋‹ค๋ฅธ CSS ์Šคํƒ€์ผ๋กœ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๋ณ€ํ™”์‹œํ‚ต๋‹ˆ๋‹ค.
์• ๋‹ˆ๋ฉ”์ด์…˜์€ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋‚˜ํƒ€๋‚ด๋Š” CSS ์Šคํƒ€์ผ๊ณผ ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ์—ฐ์†๋œ ์žฅ๋ฉด(sequence)๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ณต์ˆ˜์˜ ํ‚คํ”„๋ ˆ์ž„(@keyframes)๋“ค๋กœ ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.

   ___ ์ฐธ๊ณ ํ•˜๊ธฐ ___
  `1   @keyframes : CSS ์• ๋‹ˆ๋ฉ”์ด์…˜์—์„œ ๊ตฌ๊ฐ„์„ ์ •ํ•˜๊ณ  ๊ฐ ๊ตฌ๊ฐ„๋ณ„๋กœ ์–ด๋–ค ์Šคํƒ€์ผ์„ ์ ์šฉ์‹œํ‚ฌ์ง€ ์ •ํ•ฉ๋‹ˆ๋‹ค.


02. gif ์—์„œ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ

[1] < div > ๋ฐ•์Šค ๋งŒ๋“ค๊ธฐ

ํฌํ† ์ƒต์œผ๋กœ gif ํŒŒ์ผ์„ ํ•˜๋‚˜์”ฉ ์ด์–ด๋ถ™์ž…๋‹ˆ๋‹ค.
๊ฐ€๋กœ๋กœ ๊ธด ~ ์ด๋ฏธ์ง€ ํŒŒ์ผ์ด ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค.


03. html ์ž‘์„ฑ

[1] < div > ๋ฐ•์Šค ๋งŒ๋“ค๊ธฐ

ํฌํ† ์ƒต์œผ๋กœ gif ํŒŒ์ผ์„ ํ•˜๋‚˜์”ฉ ์ด์–ด๋ถ™์ž…๋‹ˆ๋‹ค.

<div class="timing step">
<div class="stepbox"></div>
<span class="stepBtn">
<a href="#" class="stepBtnStart">Start</a>
<a href="#" class="stepBtnStop">Stop</a>
</span>
</div>

[2] CSS ์„ค์ •ํ•˜๊ธฐ

@keyframes ์„ ์ด์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ์›€์ง์ž„์„ ์กฐ์ ˆํ•ฉ๋‹ˆ๋‹ค.

.step {
height: 700px;
background: #E7F9FF;
position: relative;
}
.step .stepbox {
width: 800px;
height: 600px;
background: url(img/walking.jpg);
border-radius: 0;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
animation: ani 1s steps(30, start) infinite; /* (์• ๋‹ˆ๋ฉ”์ด์…˜ ์ด๋ฏธ์ง€์˜ ์ด ํ”„๋ ˆ์ž„์ˆ˜, start) */
}
.step .stepbox.start {
animation-play-state: running;
}
.step .stepbox.stop {
animation-play-state: paused;
}
@keyframes ani {
0% {
background-position: 0 0;
}
100% {
background-position: -24000px 0; /* ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ด๋ฏธ์ง€์˜ ์ด ๋„ˆ๋น„ px */
}
}
.stepBtn {
position: absolute;
left: 15px;
top: 20px;
}
.stepBtn a {
background: #e16162;
color: #fff;
padding: 10px;
margin: 3px;
border-radius: 3px;
}

๊ฒฐ๊ณผ๋ณด๊ธฐ

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€