-
Notifications
You must be signed in to change notification settings - Fork 20
/
1.12 雪花纷飞的页面.html
151 lines (78 loc) · 2.16 KB
/
1.12 雪花纷飞的页面.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
150
151
<html>
<body onload="snow()" bgcolor="#FF3333">
<form id="form1" runat="server">
<script type="text/javascript">
N=100;//雪花的个数
Y=new Array();//雪花的纵坐标
X=new Array();//雪花的横坐标
S=new Array();//雪花的移动范围
A=new Array();//雪花的纵坐标
B=new Array();//雪花的纵坐标
M=new Array();//雪花的大小
V=(document.all)?0:1;//当前窗口的层数
iH=window.document.body.clientHeight;//获得当前窗口的高度
iW=window.document.body.clientWidth;//获得当前窗口的宽度
for(i=0;i<N;i++)
{
Y[i]=Math.round(Math.random()*iH);//生成每个雪花的初始纵坐标
X[i]=Math.round(Math.random()*iW);//生成每个雪花的初始横坐标
S[i]=Math.round(Math.random()*5+2);
A[i]=0;
B[i]=Math.random()*0.01+0.1;
M[i]=Math.round(Math.random()*1+1);
}
if(V)
{
for(i=0;i<N;i++)//N个雪花循环初始化
{
document.write("<layer name='sn"+i+"' left=0 top=0 bgcolor='#000000' cuip='0,0,"+M[i]+","+M[i]+"'></layer>");
}
}
else
{
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for(i=0;i<N;i++)//N个雪花循环初始化
{
document.write('<div id="si" style="position:absolute;top:0;left:0;width:'+M[i]+';height:'+M[i]+';background:#FFFFCC;font-size:'+M[i]+'"></div>');
//定义雪花为黑色
}
document.write('</div></div>');
}
function snow()
{
var H=window.document.body.clientHeight;//获得当前窗口的高度
var W=window.document.body.clientWidth;//获得当前窗口的宽度
var T=document.body.scrollTop;//获得当前窗口的纵坐标
var L=document.body.scrollLeft;//获得当前窗口的横坐标
for(i=0;i<N;i++)
{
sy=S[i]*Math.sin(90*Math.PI/180);//生成y方向的步长
sx=S[i]*Math.cos(A[i]);//生成x方向的步长
Y[i]+=sy;//更新纵坐标
X[i]+=sx;//更新横坐标
if(Y[i]>H)//如果雪花超出了屏幕
{
Y[i]=-10;//赋值给雪花纵坐标
X[i]=Math.round(Math.random()*W);//重新赋值给雪花的纵坐标
M[i]=Math.round(Math.random()*1+1);//定义雪花的大小
S[i]=Math.round(Math.random()*5+2);//定义雪花的飘动的幅度
}
if(V)
{
//重新显示每个雪花
document.all['sn'+i].left=X[i];document.layers['sn'+i].top=Y[i]+T
}
else
{
//重新显示每个雪花
si[i].style.pixelLeft=X[i];si[i].style.pixelTop=Y[i]+T
}
A[i]+=B[i];
}
setTimeout('snow()',10);//每0.01秒更新一次画面
}
</script>
</form>
</body>
</html>