-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxiaxue.html
128 lines (114 loc) · 2.87 KB
/
xiaxue.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
<!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: 10;
font-size: 1.6em;
}
.snow {
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 100%;
position: fixed;
left: 100px;
top: 300px;
opacity: 0.3;
filter: blur(4px);
z-index: 3;
}
</style>
</head>
<body>
<div class="title">
<h1>Happy Birthdays</h1>
</div>
<script type="text/javascript">
//常用方法
function random(min, max, isInt) {
var a = min + Math.random() * (max - min);
return isInt ? parseInt(a) : a;
}
var winW = window.innerWidth;
var winH = window.innerHeight;
var snow;
class Snow {
constructor() {
this.size = random(8, 20, true);
this.alpha = random(0.2, 1, false);
this.blur = random(0, 2, false);
this.x = random(0, winW, true);
this.y = random(-winH / 2, 0, true);
this.z = random(1, 20, true);
this.speed = random(1, 3, false);
this.angle = 0;
this.angleSpeed = random(0, 2 * Math.PI, false) / 100;
this.o = null;
}
draw() {
//document createElement
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.blur;
this.o.style.filter = `blur(${this.blur}px)`;
this.o.style.left = this.x + "px";
this.o.style.top = this.y + "px";
}
update() {
this.angle += this.angleSpeed;
this.x += Math.cos(this.angle);
this.y += this.speed;
this.o.style.top = this.y + "px";
this.o.style.left = this.x + "px";
if(this.y > winH + 10) {
this.y = random(-winH / 2, 0, true);
}
}
}
class Weather {
constructor(snowNum, wind) {
this.snowNum = snowNum;
this.wind = wind;
this.snowArray = [];
}
createSnow() {
for(var i = 0; i < this.snowNum; i++) {
snow = new Snow();
snow.draw();
this.snowArray.push(snow);
}
}
runSnow() {
var that = this;
function run () {
for(var i = 0; i < that.snowNum; i++) {
that.snowArray[i].update();
}
window.requestAnimationFrame(run);
}
window.requestAnimationFrame(run);
}
}
var weather = new Weather(100, 3);
weather.createSnow();
weather.runSnow();
</script>
</body>
</html>