-
Notifications
You must be signed in to change notification settings - Fork 0
/
xuehua.html
149 lines (135 loc) · 3.63 KB
/
xuehua.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body {
background-color: #11113f;
color: white;
font-family: 'Petit Formal Script', cursive;
overflow: hidden;
}
.title {
position: absolute;
text-align: center;
top: 50%;
left: 50%;
-webkit-transform: translate3d(-50%, -50%, 0);
transform: translate3d(-50%, -50%, 0);
z-index: 0;
font-size: 1.6em;
}
.snow {
position: absolute;
background-color: purple;
border-radius: 100%;
}
</style>
</head>
<body>
<div class="title">
<h1>Happy Holidays</h1>
</div>
<audio src="//katiebaca.com/codepen/merry-christmas-mr-lawrence.mp3" autoplay loop></audio>
<script type="text/javascript">
(function() {
//常用方法
function random(min, max, isInt) {
var a = min + Math.random() * (max - min);
return isInt ? parseInt(a) : a;
}
//Snow构造方法
function Snow() {
this.init();
this.draw();
}
//雪花的初始化
Snow.prototype.init = function() {
//大小 、颜色(透明度)、位置(x,y)、速度(水平方向的速度和垂直方向的速度)
this.size = random(2, 10, true);
this.alpha = random(0.3, 1, false);
this.x = random(0, Weather.width, true);
this.y = random(-Weather.height, 0, true);
this.z = random(0, 10, true);
this.wind = random(0, Weather.wind, true);
this.speed = random(1, 3, false);
this.reduce = random(1, 4, true);
this.angle = 0;
this.angleSpeed = random(0, 2 * Math.PI, false) / 100;
}
//雪花的 绘制
Snow.prototype.draw = function() {
this.o = document.createElement("div");
this.o.className = "snow";
document.body.appendChild(this.o);
this.o.style.width = this.o.style.height = this.size + "px";
this.o.style.opacity = this.alpha;
this.o.style.left = this.x + "px";
this.o.style.top = this.y + "px";
this.o.style.zIndex = this.z;
this.o.style.filter = blur(this.reduce + 'px');
}
//雪花运动
Snow.prototype.update = function() {
this.angle += this.angleSpeed;
this.x += Math.cos(this.angle);
this.x += this.wind;
this.y += this.speed;
if(this.y > Weather.height) {
this.init();
}
this.o.style.left = this.x + "px";
this.o.style.top = this.y + "px";
}
//天气对象的设置
var Weather = {
num: 100,
snowLevel: function(level) {
var a;
switch(level) {
case 'b':
a = 1000;
break;
case 'm':
a = 500;
break;
case 's':
a = 100;
break;
default:
break;
};
return Weather.num = a;
},
windDirection: 3,
width: window.innerWidth,
height: window.innerHeight,
snowArray: new Array(),
wind: 1,
createSnows: function() {
for(var i = 0; i < Weather.num; i++) {
var s = new Snow();
Weather.snowArray.push(s);
}
},
runSnows: function() {
for(var i = 0; i < Weather.num; i++) {
Weather.snowArray[i].update();
}
requestAnimationFrame(Weather.runSnows);
},
resize: function() {
Weather.width = window.innerWidth;
Weather.height = window.innerHeight;
console.log(Weather.width);
}
}
Weather.snowLevel('s');
Weather.createSnows();
Weather.runSnows();
addEventListener("resize", Weather.resize);
}());
</script>
</body>
</html>