Background Effect With CSS

 Background  Effect:-

Code:-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
         margin:0;
         padding:0;
          box-sizing:border-box;  
        }
        body{
            overflowhidden;
            height:100vh;
            background#000;
        }
        section
        {
            height:100vh;
        }
        span{
            positionabsolute;
            pointer-eventsnone;
            background#fff;
            animation: animate 5s linear infinite;
        }
        @keyframes animate {
            0%{
                transformscale(0translateY(0rotate(0deg);
            }
            10%{
                opacity1;
            }
            90%{
                opacity1;
            }
            100%{
                transformscale(1rotate(360deg);
                opacity0;
            }
        }
    </style>
</head>
<body>
    <section></section>
    <script>
        const colors = [
            '#2196f3',
            '#e91e63',
            '#ffeb3b',
            '#74ff1d'
        ]
        function createSquare(){
            const section =document.querySelector('section');
            const square = document.createElement('span');

            var size = Math.random() * 50;

            square.style.width = 20 + size + 'px';
            square.style.height = 20 + size + 'px';

            // square.style.borderRadius = 50 + size + '%'; // change in circle shape



            square.style.top = Math.random() * innerHeight + 'px';
            square.style.left = Math.random() * innerWidth + 'px';

            const bg = colors[Math.floor(Math.random() *colors.length)];
            square.style.background  = bg;


            section.appendChild(square);

            setTimeout(()=>{
                square.remove()
            },5000)
        }

        setInterval(createSquare150)
    </script>
</body>
</html>

Output:-



Comments

Popular Posts