●▲■ 개발일기

[JavaScript] Colorful Rain Animation Effects using Html CSS & Vanilla Javascript 본문

👉 javascript

[JavaScript] Colorful Rain Animation Effects using Html CSS & Vanilla Javascript

●▲■ PRINT 2021. 12. 19. 22:27

휴일에 우연히 유튜브 보다가 따라서 만들어 본 js animation.

요새 자바스크립트에 빠져 있다보니 자연스레 관심이.

 

일 때문에 자바스크립트를 많이 만지고 있는 요즘.

어디에 기록을 할까 고민하다가 티스토리 계정 생성해서 이제 여기에 메모할 예정.

 

 

 

출처 : https://www.youtube.com/watch?v=YhXxBhInJMI

<!DOCTYPE html>
<html lang="en">
<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>JS -- Rain effect</title>
</head>

<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    body {
        background: #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, #0ff);
    }
    i:nth-child(3n + 2) {
        background: linear-gradient(transparent, #0f0);
    }
    i:nth-child(3n + 3) {
        background: linear-gradient(transparent, #f00);
    }
    @keyframes animate
    {
        0%
        {
            transform: translateY(-200px);
        }
        100%
        {
            transform: translateY(calc(100vh + 200px));
        }
    }
</style>


<body>
    <script>
        function rain() {
            let amount = 100;
            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 = 0.2 + size+'px';
                drop.style.left = posX + 'px';
                drop.style.animationDelay = delay+'s';
                drop.style.animationDuration = 1 + duration+'s';
                body.appendChild(drop);
                i++
            }
        }

        rain();
    </script>
</body>
</html>

Colorful Rain Animation Effects using Html CSS &amp; Vanilla Javascript.html
0.00MB