-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxuehua.html
139 lines (128 loc) · 2.94 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>雪花</title>
</head>
<style type="text/css">
body{
background-color: midnightblue;
}
.a{
position: absolute;
margin: auto;
text-align: center;
left: 0px;
right: 0px;
top: 180px;
bottom: 0px;
color: white;
font-size: 40px;
z-index: 0;
}
.snow{
width: 20px;
height: 20px;
background-color: white;
border-radius: 100%;
position: fixed;
opacity: 0.8;
filter: blur(4px);
}
</style>
<body>
<div class="a">
<h1>Happy Holidays</h1>
</div>
<!--<div class="snow"></div>-->
<script type="text/javascript">
// var snow=document.querySelector(".snow");
// var y=0;
// var x=Math.random()*window.innerWidth;
// snow.style.left=x+"px";
// function run () {
// y=y+10;
// console.log(y);
// if(y>window.innerHeight+10)
// {
// y=0;
// x=Math.random()*window.innerWidth;
// }
// snow.style.top=y+"px";
// snow.style.left=x+"px";
// setTimeout(run,100);
// }
// run();
var snow;
var winW = window.innerWidth;
var winH = window.innerHeight;
function random(min,max,isInt)
{
var a=min+Math.random()*(max-min);
return isInt?parseInt(a):a;
}
class Snow {
constructor(){
this.size=random(8,15,true);
this.alpha=random(0.2,0.5,false);
this.blur=random(1,2,false);
this.x=random(0,window.innerWidth,true);
this.y=random(-(window.innerHeight/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(){
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.top=this.y+"px";
this.o.style.left=this.x+"px";
}
update() {
this.angle += this.angleSpeed;
this.x += Math.cos(this.angle)*weather.wind;
this.y += this.speed;
this.o.style.top = this.y + "px";
this.o.style.left = this.x + "px";
if(this.y > window.innerHeight + 10) {
this.y = random(-window.innerHeight / 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(200, 3);
weather.createSnow();
weather.runSnow();
</script>
</body>
</html>