비전공자 개발일기

ColorFul Rain 본문

Javascript

ColorFul Rain

HiroDaegu 2022. 7. 31. 00:44
728x90
SMALL

 

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>COLORFUL RAIN</title>
  <link rel="stylesheet" href="style.css">
  <script defer src="main.js"></script>
</head>
<body>
  
</body>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: #000;
  overflow: hidden;
  height: 100vh;
}

i {
  position: absolute;
  height: 200px;
  background: linear-gradient(transparent, #FFF);
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  animation: animate 5s linear infinite;
}

i:nth-child(3n + 1) {
  background:linear-gradient(transparent, #ABFFB2);
}

i:nth-child(3n + 2) {
  background:linear-gradient(transparent, #FFC4B3);
}

i:nth-child(3n + 3) {
  background:linear-gradient(transparent, #E3FFAB);
}

@keyframes animate {
  0% {
    transform: translateY(-200px);
  }
  100% {
    transform: translateY(calc(100vh + 200px));
  }
}
function rain() {
  let amount = 80;
  let body = document.querySelector("body");
  let i = 0;
  while(i < amount) {
    let drop = document.createElement('i');

    let size = Math.random() * 5;
    let posX = Math.floor(Math.random() * window.innerWidth);
    let delay = Math.random() * - 20;
    let duration = Math.random() * 5;

    drop.style.width = size + 'px';
    drop.style.left = posX + 'px';
    drop.style.animationDelay = delay + 's';
    drop.style.animationDuration = 1 + duration + 's';
    body.appendChild(drop);
    i++;
  }
}

rain();
728x90
LIST

'Javascript' 카테고리의 다른 글

Word Guess Game  (0) 2022.08.12
Search Filter  (0) 2022.08.02
Notification Bell  (0) 2022.07.27
Tic Tae Toc  (0) 2022.07.09
Chatbot  (0) 2022.07.08