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

[CSS] ๋กœ๋”ฉ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ

by ์ฝ”๋”ฉ๊ณต์ฑ… 2022. 9. 25.
๋ฐ˜์‘ํ˜•

๋กœ๋”ฉ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๋กœ๋”ฉ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค์–ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

HTML ์ฝ”๋“œ

loader ํด๋ž˜์Šค๊ฐ’์„ ๊ฐ€์ง„ div ์•ˆ์— ball ํด๋ž˜์Šค๊ฐ’ div๋ฅผ 10๊ฐœ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋„๋ก ํ•œ๋‹ค.

<div class="loader">
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
</div>

CSS ์ฝ”๋“œ

ball ํด๋ž˜์Šค๋ฅผ ์ง€๋‹Œ div์˜ ํ˜•ํƒœ๋ฅผ ๋งŒ๋“ค์–ด ์ค€ ๋‹ค์Œ nth-child๋ฅผ ์ด์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋”œ๋ ˆ์ด๋ฅผ ์ฃผ๊ณ  ๋งˆ์ง€๋ง‰์œผ๋กœ ํ‚คํ”„๋ ˆ์ž„์„ ํ†ตํ•ด ๋ณธ๊ฒฉ์ ์œผ๋กœ ์›€์ง์ž„์„ ์ฃผ๋„๋ก ํ•œ๋‹ค.

body {
  background-color: #b38dff;
}
.loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  animation: spin .6s linear infinite reverse;
}

.ball {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 100%;
  animation: spin 1s infinite ease-in-out;
}

.ball:after {
  position: absolute;
  content: '';
  background-color: #fff;
  width: 5px;
  height: 5px;
  border-radius: 100%;
  top: 0;
}

.ball:nth-child(2){
  animation-delay: -0.1s;
}
.ball:nth-child(3){
  animation-delay: -0.2s;
}
.ball:nth-child(4){
  animation-delay: -0.3s;
}
.ball:nth-child(5){
  animation-delay: -0.4s;
}
.ball:nth-child(6){
  animation-delay: -0.5s;
}
.ball:nth-child(7){
  animation-delay: -0.6s;
}
.ball:nth-child(8){
  animation-delay: -0.7s;
}
.ball:nth-child(9){
  animation-delay: -0.8s;
}
.ball:nth-child(10){
  animation-delay: -0.9s;
}

@keyframes spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

๊ฒฐ๊ณผ๋ฌผ

๋กœ๋”ฉ ํ™”๋ฉด ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์™„์„ฑ๋์Šต๋‹ˆ๋‹ค~!๐Ÿ˜Š

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€


Reference Book

JavaScript
HTML
CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.