css3-雪花飘落效果

    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        html,body{
            width: 100%;
            height: 100%;
        }
        body{
            background-image: url('./img/b.jpeg');
            background-size: 100% 100%;
            background-repeat: no-repeat;
            overflow: hidden;
        }
        .sn{
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
        }
        .sn .snow{
            width: 100%;
            height: 100%;
            background-image: url('./img/xt.png');
            background-position: 0 0;
            background-size: cover;
            position: absolute;
            left: 0;
            top: 0;
        }
        .sn .snow-1{
            filter: blur(4px);
            animation: animate1 15s linear infinite;
        }
        .sn .snow-2{
            filter: blur(3px);
            animation: animate2 15s linear infinite;
            background-size: 800px;
        }
        .sn .snow-3{
            filter: blur(1px);
            animation: animate3 15s linear infinite;
            background-size: 300px;
       
        }
        @keyframes animate1{
            0%{
                background-position: 0 0;
            }
            100%{
                background-position: 150px 100vh;
            }
        }
        @keyframes animate2{
            0%{
                background-position: 0 0;
            }
            100%{
                background-position: 300px 800px;
            }
        }
        @keyframes animate3{
            0%{
                background-position: 0 0;
            }
            100%{
                background-position: 0100vh;
            }
        }
    </style>
</head>
<body>
    <section class="sn">
    <span class="snow snow-1"></span>
    <span class="snow snow-2"></span>
    <span class="snow snow-3"></span>
</section>
</body>

效果图

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的HTML+CSS+JS实现雪花飘飘效果的代码,其中使用了JavaScript的random方法实现了雪花的随机位置和下落速度。 HTML代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>雪花飘飘</title> <style> body { background-color: #000; } .snow { position: absolute; width: 10px; height: 10px; background-color: #fff; border-radius: 50%; pointer-events: none; z-index: 9999; animation: falling 5s linear infinite; } @keyframes falling { 0% { transform: translateY(-100%); } 100% { transform: translateY(100%); } } </style> </head> <body> <script src="snow.js"></script> </body> </html> ``` CSS代码: ```css body { background-color: #000; } .snow { position: absolute; width: 10px; height: 10px; background-color: #fff; border-radius: 50%; pointer-events: none; z-index: 9999; animation: falling 5s linear infinite; } @keyframes falling { 0% { transform: translateY(-100%); } 100% { transform: translateY(100%); } } ``` JavaScript代码: ```javascript function createSnow() { const snow = document.createElement('div'); snow.classList.add('snow'); snow.style.left = Math.random() * window.innerWidth + 'px'; snow.style.animationDuration = Math.random() * 5 + 5 + 's'; document.body.appendChild(snow); setTimeout(() => { snow.remove(); }, 5000); } setInterval(createSnow, 100); ``` 代码说明: 1. HTML文件中引入了一个JavaScript文件`snow.js`,该文件用于创建雪花元素。 2. CSS文件中定义了雪花元素的样式,包括位置、大小、颜色、动画等。 3. JavaScript文件中定义了一个`createSnow()`函数,用于创建雪花元素。函数中使用`Math.random()`方法生成一个随机的左侧位置和动画时长,然后将雪花元素添加到页面中。 4. 使用`setInterval()`方法每隔100毫秒调用一次`createSnow()`函数,从而实现不断产生雪花效果。 注意:这里的雪花效果比较简单,仅作为示例参考。实际应用中需要根据具体需求进行调整和优化。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值