Moon Background Animation

Home / Web Code Snippet / Moon Background Animation

Moon Background Animation


https://youtube.com/shorts/bqRpONp4DM0?si=ngHTzUDXTOU3SmqN

HTML CODE:-

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>
    <div class="container">
        <div class="moon">
            <img src="img/moon.png">
        </div>
    </div>
</body>
</html>

CSS CODE:-

*{
            padding: 0px;
            margin: 0px;
            box-sizing: border-box;
        }
        .container{
            position: relative;
            width: 100%;
            min-height: 100vh;
            background: black;
            overflow: hidden;
        }
        .container:before {
                content: "";
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background-image: url("https://t4.ftcdn.net/jpg/02/43/75/73/360_F_243757367_gBpS6R5c8DB7pL5gw9gi9KXlzFfbdZOA.jpg");
                background-size: cover;
                transform: scale(1.2);
                animation: animate 8s linear infinite;
            }
            @keyframes animate{
                0% {
                    background-position: 0 0;
                
                }
   
                100% {
                    background-position: 10% 80%;
                   /* transform: scale(2);*/
                }
            }
            .moon{
                position: absolute;
                left: -50px;
                animation: animate1 8s linear infinite;
            }
            @keyframes animate1{
                0%{
                    transform: rotate(10deg);
                }
                50%{
                    transform: rotate(-10deg);
                }
                100%{
                    transform: rotate(10deg);
                }
            }
            img{
                width: 400px;
            }