Javascript设计漫天雪花

原代码插入到

 1<body>下面:<script language="JavaScript">   
 2<!--   
 3N = 40;   
 4Y = new Array();   
 5X = new Array();   
 6S = new Array();   
 7A = new Array();   
 8B = new Array();   
 9M = new Array();   
10V = (document.layers)?1:0; iH=(document.layers)?window.innerHeight:window.document.body.clientHeight;   
11iW=(document.layers)?window.innerWidth:window.document.body.clientWidth;   
12for (i=0; i < N; i++){   
13Y[i]=Math.round(Math.random()*iH);   
14X[i]=Math.round(Math.random()*iW);   
15S[i]=Math.round(Math.random()*5+2);   
16A[i]=0;   
17B[i]=Math.random()*0.1+0.1;   
18M[i]=Math.round(Math.random()*1+1);   
19}   
20if (V){   
21for (i = 0; i < N; i++)   
22{document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFF0' CLIP='0,0,"+M[i]+","+M[i]+"'></LAYER>")}   
23}   
24else{   
25document.write('<div style="position:absolute;top:0px;left:0px">');   
26document.write('<div style="position:relative">');   
27for (i = 0; i < N; i++)   
28{document.write('<div id="si" style="position:absolute;top:0;left:0;width:'+M[i]+';height:'+M[i]+';background:#fffff0;font-size:'+M[i]+'"></div>')}   
29document.write('</div></div>');   
30}   
31function snow(){   
32var H=(document.layers)?window.innerHeight:window.document.body.clientHeight;   
33var W=(document.layers)?window.innerWidth:window.document.body.clientWidth;   
34var T=(document.layers)?window.pageYOffset:document.body.scrollTop;   
35var L=(document.layers)?window.pageXOffset:document.body.scrollLeft;   
36for (i=0; i < N; i++){   
37sy=S[i]*Math.sin(90*Math.PI/180);   
38sx=S[i]*Math.cos(A[i]);   
39Y[i]+=sy;   
40X[i]+=sx;   
41if (Y[i] > H){   
42Y[i]=-10;   
43X[i]=Math.round(Math.random()*W);   
44M[i]=Math.round(Math.random()*1+1);   
45S[i]=Math.round(Math.random()*5+2);   
46}   
47if (V){document.layers['sn'+i].left=X[i];document.layers['sn'+i].top=Y[i]+T}   
48else{si[i].style.pixelLeft=X[i];si[i].style.pixelTop=Y[i]+T}   
49A[i]+=B[i];   
50}   
51setTimeout('snow()',10);   
52}   
53//-->   
54</script>   
55把<body>中的内容改为:   
56<body bgcolor="#ffffff" onload="snow()"></body></body></body>
Published At
Categories with 网页设计
Tagged with
comments powered by Disqus