-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmySnow.html
107 lines (101 loc) · 2.43 KB
/
mySnow.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>mySnow- oH!!!Sexy!</title>
<style type="text/css">
body,div{margin: 0;padding: 0;}
#curtain{
width: 1600px;
height: 800px;
background-color: #111123;
}
.snow{
width: 10px;
height: 10px;
border-radius: 50%;
background: #fff;
position: absolute;
animation: mysnow 10s;
}
@keyframes mysnow{
0%{opacity: 0;}
50%{opacity: 1;}
100%{opacity: 0;}
}
.empty{
display: none;
}
</style>
<script type="text/javascript">
window.onload = function() {
var $ = function(id) {
return typeof id === "string" ? document.getElementById(id) : id
};
var curtain = $("curtain");
var maxWidth = curtain.clientWidth - 50;
var maxHeight = curtain.clientHeight;
var snowControl = function() {};
snowControl.prototype = {
Obj: [],
maxCount: 400,
count: 0,
Prepare: function() {
for (var i = 0; i < this.maxCount; i++) {
var o = {
positionX: Math.ceil(Math.random() * maxWidth),
positionY: Math.ceil(Math.random() * 50),
speed: Math.ceil(Math.random() * 5 + 3),
shake: Math.ceil(Math.random() * 3)
};
this.Obj.push(o);
};
},
Init: function() {
if (this.Obj != null) {
var oDiv = document.createElement("div");
oDiv.className = "snow";
var now = this.Obj.shift();
oDiv.style.top = now.positionY + "px";
oDiv.style.left = now.positionX + "px";
curtain.appendChild(oDiv);
this.Move(oDiv, now);
++this.count;
} else {
return false;
}
},
Move: function(oDiv, now) {
var timer = setInterval(function() {
if (now.positionX < maxWidth || now.positioY < maxHeight) {
now.positionY = now.positionY + now.speed;
now.positionX = now.positionX + now.shake;
oDiv.style.top = now.positionY + "px";
oDiv.style.left = now.positionX + "px";
} else {
now.positionX = Math.ceil(Math.random() * maxWidth);
now.positionY = Math.ceil(Math.random() * 50);
}
}, 30);
},
Letsgo: function() {
var oThis = this;
var gotimer = setInterval(function() {
if (oThis.count == oThis.maxCount) {
clearInterval(gotimer);
} else {
oThis.Init();
}
}, 400);
}
};
var snow = new snowControl();
snow.Prepare();
snow.Letsgo();
};
</script>
</head>
<body>
<div id="curtain"></div>
</body>
</html>