<!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>雪花特效</title>
<style>
* {
padding: 0;
margin: 0;
}
.content {
width: 100vw;
height: 100vh;
background: url(https://xn--xu0a.cn/api/dn/) center center no-repeat;
background-size: cover;
}
#rainBox {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
pointer-events: none;
}
.rain {
position: absolute;
width: 2px;
height: 50px;
background: linear-gradient(rgba(255, 255, 255, .3), rgba(255, 255, 255, .6));
}
</style>
<style type="text/css">
@font-face {
font-family: TencentSans;
src: url("chrome-extension://lkjkfecdnfjopaeaibboihfkmhdjmanm/static/fonts/TencentSans.woff2");
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
window.onload = function () {
var minSize = 5; //最小字体
var maxSize = 50;//最大字体
var newOne = 100; //生成雪花间隔
var flakColor = "#fff"; //雪花颜色
var flak = $("<div></div>").css({position:"absolute","top":"0px"}).html("❉");//定义一个雪花
var dhight = $(window).height(); //定义视图高度
var dw =$(window).width()-80; //定义视图宽度
setInterval(function(){
var sizeflak = minSize+Math.random()*maxSize; //产生大小不等的雪花
var startLeft = Math.random()*dw; //雪花生成是随机的left值
var startOpacity = 0.7+Math.random()*0.3; //随机透明度
var endTop= dhight-100; //雪花停止top的位置
var endLeft= Math.random()*dw; //雪花停止的left位置
var durationfull = 5000+Math.random()*5000; //雪花飘落速度不同
flak.clone().appendTo($("body")).css({
"left":startLeft ,
"opacity":startOpacity,
"font-size":sizeflak,
"color":flakColor
}).animate({
"top":endTop,
"left":endLeft,
"apacity":0.1
},durationfull,function(){
$(this).remove()
});
},newOne);
}
</script>
</head>
<body>
<div class="content">
<div id="rainBox"></div>
</div>
</body>
</html>