-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs-snow-3-me.html
More file actions
84 lines (74 loc) · 1.76 KB
/
Copy pathjs-snow-3-me.html
File metadata and controls
84 lines (74 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div,body{
margin: 0;
padding: 0;
}
#snow-bg{
width: 800px;
height: 800px;
background: #231123;
}
.snow{
width: 10px;
height: 10px;
background: #fff;
border-radius: 50%;
position: absolute;
animation: mysnow 10s;
}
@keyframes mysnow{
0%{opacity: 0;}
50%{opacity: 1;}
100%{opacity: 0;}
}
</style>
</head>
<script type="text/javascript">
window.onload=function(){
var curtain=document.getElementById("snow-bg");
var maxWidth=curtain.clientWidth;
var maxHeight=curtain.clientHeight;
var snowProp=[];//用于保存每一个雪花
var snowDiv=[];//用于保存每个雪花Div
var snow=function(){};
snow.prototype.init=function(){
setInterval(function(){
var o={
positionX:Math.random()*maxWidth,
positionY:Math.random()*50,
speed:Math.random()*10,
shake:Math.random()*2+(-1),
};
var oDiv=document.createElement("div");
oDiv.style.top=o.positionY+"px";
oDiv.style.left=o.positionX+"px";
oDiv.className="snow";
curtain.appendChild(oDiv);
snowProp.push(o);
snowDiv.push(oDiv);
} ,400);
};
//失败品,正确的做法应该是先描述一个雪花的动作,然后量产,而不是一次性产生好多雪花一起来控制他们的行为
snow.prototype.move=function(){
}
var snowObj=new snow();
snowObj.init();
// window.requestAnimFrame = (function() {
// return window.requestAnimationFrame ||
// window.webkitRequestAnimationFrame ||
// window.mozRequestAnimationFrame ||
// function(callback) {
// window.setTimeout(callback, 1000 / 60);
// };
// })();
}
</script>
<body>
<div id="snow-bg"></div>
</body>
</html>