This commit is contained in:
muqing 2024-08-07 18:26:28 +08:00
parent 0cc14dcf8a
commit 45a8c50e93

View File

@ -32,9 +32,8 @@
## 反馈
我们目前没有写反馈的接口和功能 你可以加群 点击链接加入群聊【铁锈助手】https://qm.qq.com/q/dUfOK04pj2 在此反馈
## 特别鸣谢 (参与项目开发)
<!DOCTYPE html>
<html>
## 特别鸣谢 (参与项目开发)<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<style>
@ -42,7 +41,6 @@
margin: 0;
padding: 0;
}
#box {
width: 100vw;
height: 100vh;
@ -52,13 +50,10 @@
}
</style>
</head>
<body>
<div id="box">
</div>
</body>
<script>
(function () {
var screenWidth = screen.availWidth; // 获取屏幕宽度
@ -73,7 +68,6 @@
this.init(); // 初始化
this.start(); // 开始下雪
}
// 获取相关随机数据的方法
Snow.prototype.getRandomThings = function (type) {
var res;
@ -91,7 +85,6 @@
}
return res;
}
Snow.prototype.init = function () {
this.box.style.width = screenWidth + 'px'; // 设置容器宽度为屏幕宽度
this.box.style.height = screenHeight + 'px'; // 设置容器高度为屏幕高度
@ -111,7 +104,6 @@
}
box.appendChild(fragment); // 将文档片段添加到容器中
}
Snow.prototype.start = function () {
var that = this;
var num = 0;
@ -127,7 +119,6 @@
})(snow, num)
}
}
// 针对每个雪花的定时处理
Snow.prototype.doStart = function (snow) {
var that = this;
@ -143,7 +134,6 @@
// 重新回到天上开始往下
increTop = that.getRandomThings('incre');
increLeft = that.getRandomThings('increLeft');
// 重新随机属性
var left = that.getRandomThings('left');
var top = that.getRandomThings('top');
@ -154,30 +144,23 @@
y = top;
x = left;
n = 0;
return;
}
// 加上系数当随机数大于0.5时速度加快小于0.5时速度减慢,形成飘动效果
x += Math.random() > 0.5 ? increLeft * 1.1 : increLeft * 0.9;
y += Math.random() > 0.5 ? increTop * 1.1 : increTop * 0.9;
// 设置left和top值使雪花动起来
s.style.left = x + 'px';
s.style.top = y + 'px';
}, speed); // 每隔speed毫秒执行一次定时器中的代码
})(snow)
}
// 获取元素的样式值
function getStyle(obj, prop) {
var prevComputedStyle = document.defaultView ? document.defaultView.getComputedStyle(obj, null) : obj.currentStyle;
return prevComputedStyle[prop];
}
new Snow(300, 30); // 创建一个Snow对象传入雪花数量和每批下落的雪花数量
})()
</script>
</html>