JavaScript to achieve Snow (Snow) effect

Source: Internet
Author: User
Tags array sin visibility
Javascript

Code 1:

<title>happy New year</title>
<body bgcolor= "#ff3300" leftmargin= "0" topmargin= "0" aaad98>
<script language= "JavaScript" >
<!--
N = 100;
Y = new Array ();
X = new Array ();
S = new Array ();
A = new Array ();
B = new Array ();
M = new Array ();
V = (document.layers)? 1:0;
Ih= (document.layers) window.innerHeight:window.document.body.clientHeight;
iw= (document.layers) window.innerWidth: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.1+0.1;
M[i]=math.round (Math.random () *1+1);
}
if (V) {
for (i = 0; i < N; i++)
{document.write ("<layer name= ' sn" +i+ "' left=0 top=0 ' bgcolor= ' #ffffff ' clip= ' 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++)
{document.write (' <div id= "si" style= "position:absolute;top:0;left:0;width: ' +m[i]+ '; height: ' +m[i]+ '; background : #ffffff; font-size: ' +m[i]+ ' "></div> ')}
document.write (' </div></div> ');
}
Function Snow () {
var h= (document.layers) window.innerHeight:window.document.body.clientHeight;
var w= (document.layers) window.innerWidth:window.document.body.clientWidth;
var t= (document.layers) Window.pageYOffset:document.body.scrollTop;
var l= (document.layers) window.pageXOffset:document.body.scrollLeft;
for (i=0 i < N; i++) {
Sy=s[i]*math.sin (90*math.pi/180);
Sx=s[i]*math.cos (A[i]);
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.layers[' sn ' +i].left=x[i];d ocument.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 () ', 20);
}
-->
</script>


Code 2:

<body bgcolor= #ee3300 >
<style>
. drop {position:absolute; width:3; FILTER:FLIPV (), Fliph (); font-size:40; Color: #ffffff}
</style>
<script language= "JavaScript" >

Snow = false;   False-rain; True-snow
Snowsym = "*" File://These are the symbols for each
Rainsym = "*" File://You can put images here.
Howmany = File://How many drops/snowflakes?

/**************do not need to change anything below***********/
if (snow) {sym = Snowsym; speed=1; angle=10; Drops=howmany}
Else{sym = Rainsym; speed=30; drops=howmany; angle=6}
Movex =-speed/angle; Movey = speed; Count = 0;

function Moverain () {
for (move = 0; move < drops; move++) {
Xx[move]+=movex; Yy[move]+=mv[move];
hmm = Math.Round (Math.random () *1);
if (Xx[move] < 0) {Xx[move] = maxx+10;}
if (Yy[move] > Maxy) {yy[move] = 10;}
Drop[move].left = Xx[move]
Drop[move].top = Yy[move]+document.body.scrolltop;
}settimeout (' Moverain () ', ' 1 ')}

</script>
<script language= "JavaScript" >

if (document.all) {
drop = new Array (); xx = new Array (); yy = new Array (); MV = new Array ()
ly = "Document.all[\ '"; st = "\].style"
for (make = 0; make < drops; make++) {
document.write (' <div id= ' drop ' +make+ ' class=drop> ' +sym+ ' </div> ');
Drop[make] = eval (ly+ ' drop ' +make+st);
Maxx = document.body.clientwidth-40
Maxy = document.body.clientheight-40
Xx[make] = Math.random () *maxx;
Yy[make] = -100-math.random () *maxy;
Drop[make].left = Xx[make]
Drop[make].top = Yy[make]
Mv[make] = (Math.random () *5) +speed/16;
Drop[make].fontsize = (Math.random () *10) +20;
if (snow) {col = ' white '}else{col = ' white '}
Drop[make].color = col;
}
Window.onload=moverain
}
</script>
</body>

Code 3:

<body bgcolor= #ee3300 >
<script language= "JavaScript1.2" >
<!--
var no = 25;
var speed = 10;
var snowflake = "/xrssfile/2006-8/31/200683122039997.gif";

var ns4up = (document.layers)? 1:0;
var ie4up = (document.all)? 1:0;
var dx, XP, YP;
var am, STX, sty;
var i, doc_width = a, doc_height = 600;
if (ns4up) {
Doc_width = Self.innerwidth;
Doc_height = Self.innerheight;
else if (ie4up) {
Doc_width = Document.body.clientWidth;
Doc_height = Document.body.clientHeight;
}
DX = new Array ();
XP = new Array ();
YP = new Array ();
am = new Array ();
STX = new Array ();
sty = new Array ();
for (i = 0; i < no; + i) {
Dx[i] = 0;
Xp[i] = Math.random () * (DOC_WIDTH-50);
Yp[i] = Math.random () *doc_height;
Am[i] = Math.random () *20;
Stx[i] = 0.02 + math.random ()/10;
Sty[i] = 0.7 + math.random ();
if (ns4up) {
if (i = = 0) {
document.write ("<layer name=\" dot "+ i +" \ "left=\" 15\ ");
document.write ("top=\" 15\ "visibility=\" show\ ">document.write (snowflake + "border=\" 0\ "></layer>");
} else {
document.write ("<layer name=\" dot "+ i +" \ "left=\" 15\ ");
document.write ("top=\" 15\ "visibility=\" show\ ">document.write (snowflake + "border=\" 0\ "></layer>");
}
else if (ie4up) {
if (i = = 0) {
document.write ("<div id=\" dot "+ i +" \ "style=\" POSITION: ");
document.write ("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write ("visible; top:15px; Left:15px;\ ">document.write (snowflake + "border=\" 0\ "></div>");
} else {
document.write ("<div id=\" dot "+ i +" \ "style=\" POSITION: ");
document.write ("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write ("visible; top:15px; Left:15px;\ ">document.write (snowflake + "border=\" 0\ "></div>");
}
}
}
function snowns () {//Netscape main animation function
for (i = 0; i < no; + i) {//iterate for every dot
Yp[i] + = Sty[i];
if (Yp[i] > doc_height-50) {
Xp[i] = Math.random () * (doc_width-am[i]-30);
Yp[i] = 0;
Stx[i] = 0.02 + math.random ()/10;
Sty[i] = 0.7 + math.random ();
Doc_width = Self.innerwidth;
Doc_height = Self.innerheight;
}
Dx[i] + = Stx[i];
document.layers["dot" +i].top = yp[i];
document.layers["dot" +i].left = Xp[i] + am[i]*math.sin (dx[i));
}
SetTimeout ("snowns ()", speed);
}
function Snowie () {//IE main animation function
for (i = 0; i < no; + i) {//iterate for every dot
Yp[i] + = Sty[i];
if (Yp[i] > doc_height-50) {
Xp[i] = Math.random () * (doc_width-am[i]-30);
Yp[i] = 0;
Stx[i] = 0.02 + math.random ()/10;
Sty[i] = 0.7 + math.random ();
Doc_width = Document.body.clientWidth;
Doc_height = Document.body.clientHeight;
}
Dx[i] + = Stx[i];
document.all["dot" +i].style.pixeltop = yp[i];
document.all["dot" +i].style.pixelleft = Xp[i] + am[i]*math.sin (dx[i));
}
SetTimeout ("Snowie ()", speed);
}
if (ns4up) {
Snowns ();
else if (ie4up) {
Snowie ();
}
-->
</script>
</body>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.