css3夜晚星空


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>css3动画</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .container {
            width: 100vw;
            height: 100vh;
            background-color: #000;
        }

        .moon {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: #F5FFFA;
            box-shadow: 0 0 60px #F5FFFA;
            position: absolute;
            left: 80%;
            top: 150px;
            animation: myMoon 20s linear;
        }

        @keyframes myMoon {
            0% {
                left: 60%;
                top: 350px;
                opacity: 0;
            }

            100% {
                left: 80%;
                top: 150px;
                opacity: 1;
            }
        }

        img {
            width: 8px;
            height: 8px;
            opacity: 0;
            position: absolute;
            left: 0px;
            top: 0px;
            animation: myStar 2s ease-in-out infinite;
        }

        @keyframes myStar {
            0% {
                opacity: 0;
            }

            50% {
                opacity: 0.4;
            }

            100% {
                opacity: 0;
            }
        }

        .star {
            width: 1px;
            display: block;
            position: absolute;
            background-color: transparent transparent transparent rgba(255, 255, 255, .5);
            opacity: 0;
            animation: star 4s linear infinite;
        }

        .star::after {
            content: '';
            display: block;
            border: 1px solid #fff;
            border-width: 0px 90px 2px 90px;
            border-color: transparent transparent transparent rgba(255, 255, 255, .5);
            transform: rotate(-45deg);
        }

        @keyframes star {
            0% {
                opacity: 0;
            }

            30% {
                opacity: 1;
            }

            100% {
                opacity: 0;
                transform: translate(-500px, 300px);
            }
        }
    </style>
</head>

<body>

    <div class="container">
        <div class="moon"></div>
    </div>
    <script>
        var width = document.body.clientWidth - 20
        var height = document.body.clientHeight - 20

        //随机生成星星
        for (var i = 0; i < 70; i++) {
            var img = document.createElement('img')
            document.body.appendChild(img)
            img.src = './imgs/star.png'
            img.style.left = Math.random() * width + 'px'
            img.style.top = Math.random() * height + 'px'
            img.style.animationDelay = Math.random() * 3 + 's' //添加动画延迟时间
        }

        //随机生成流星
        for (var i = 0; i < 10; i++) {
            var lx = document.createElement('div')
            lx.className = 'star'
            lx.style.right = (Math.random() * 400 + 150) + 'px'
            lx.style.top = (Math.random() * 200 + 100) + 'px'
            lx.style.animationDelay = Math.random() * 3 * i + 's' //添加动画延迟时间
            document.body.appendChild(lx)
        }
    </script>
</body>

</html>

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦逼的猿宝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值