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

[CSS] ๊ณต์ด ์ •์‹ ์—†์ด ํŠ€๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ

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

๊ณต์ด ํŠ€๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐโšฝ

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

HTML ์ฝ”๋“œ

<div class="wrapper">
  <div></div>
</div>
<div class="wrapper">
  <div></div>
</div>
<div class="wrapper">
  <div></div>
</div>
<div class="wrapper">
  <div></div>
</div>
<div class="wrapper">
  <div></div>
</div>

CSS ์ฝ”๋“œ

linear-gradient๋กœ ๊ทธ๋ผ๋””์–ธํŠธ ํšจ๊ณผ ๋ฐฐ๊ฒฝ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ position ์†์„ฑ๊ณผ animation, @keyframes ๋“ฑ์„ ์ž˜ ํ™œ์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์™„์„ฑ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

* {
  box-sizing: border-box;
}
body {
  background: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0;
}
.wrapper {
  position: absolute;
  animation: x 1s ease-in-out alternate infinite 0s both;
}
.wrapper:nth-of-type(2) {
  animation-delay: 0.1s;
}
.wrapper:nth-of-type(3) {
  animation-delay: 0.2s
}
.wrapper:nth-of-type(4) {
  animation-delay: 0.3s
}
.wrapper:nth-of-type(5) {
  animation-delay: 0.4s
}

.wrapper > div {
  width: 50px;
  height: 50px;
  background-color: #fff;
  border-radius: 100%;
  margin: 40px;
  animation: y 1s linear infinite 0s both;
}
.wrapper:nth-of-type(2) > div {
  animation-delay: 0.1s;
  height: 40px;
  width: 40px;
  opacity: 0.8;
}
.wrapper:nth-of-type(3) > div {
  animation-delay: 0.2s;
  height: 30px;
  width: 30px;
  opacity: 0.6;
}
.wrapper:nth-of-type(4) > div {
  animation-delay: 0.3s;
  height: 20px;
  width: 20px;
  opacity: 0.4;
}
.wrapper:nth-of-type(5) > div {
  animation-delay: 0.4s;
  height: 10px;
  width: 10px;
  opacity: 0.2;
}

@keyframes x {
  0% {
    transform:translatex(-100px);
  }
  100% {
    transform:translatex(100px);
  }
}

@keyframes y {
  25% {
    transform:translatey(-50px);
  }
  0%,50%,100% {
    transform:translatey(0);
  }
  75% {
    transform:translatey(50px);
  }
}

๊ฒฐ๊ณผ๋ฌผ

์ •์‹ ์—†์ด ํŠ€๋Š” ๊ณต ์• ๋‹ˆ๋ฉ”์ด์…˜ ์™„์„ฑ์ž…๋‹ˆ๋‹ค~๐Ÿคช ์•„์ด๊ณ  ์ •์‹ ์—†๋‹ค^^

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€


Reference Book

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