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