Implementation of Dynamic background effects generated by JavaScript, javascript background
This article describes how to implement the dynamic rain background effect generated by JavaScript. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows: <HTML>
<HEAD>
<TITLE> Effect of dynamic rain background generated by JavaScript </TITLE>
</HEAD>
<BODY bgcolor = "# fef4d2">
<Center>
<Script language = JavaScript>
<! -- [Step 1]: set the number of raindrops here -->
Var rainsize = 40;
<! -- [Step 2]: the speed of rain can be changed here, and the speed of a large value is slow -->
Var speed = 10;
Var x = new Array ();
Var y = new Array ();
Var r = new Array ();
Var cx = new Array ();
Var cy = new Array ();
Var doc_width = document. body. clientWidth;
Var doc_height = document. body. clientHeight;
For (I = 0; I <rainsize; ++ I ){
InitRain ();
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; \"> <font color = \ "blue \"> ");
Document. write (", </font> </div> ");}
Else {
Document. write ("<div id = \" dot "+ I +" \ "style = \" POSITION :");
Document. write ("absolute; Z-INDEX:" + I + "; VISIBILITY :");
Document. write ("visible; TOP: 15px; LEFT: 15px; \"> <font color = \ "blue \"> ");
Document. write (",. </font> </div> ");}
}
Function initRain (){
A = 6;
R [I] = 1;
Sn = Math. sin ();
Cs = Math. cos ();
Cx [I] = Math. random () * doc_width + 1;
Cy [I] = Math. random () * doc_height + 1;
X [I] = r [I] * sn + cx [I];
Y [I] = cy [I];
}
Function raindropIE (){
For (I = 0; I <rainsize; ++ I ){
UpdateRain ();
If (x [I] <= 1) | (x [I]> = (doc_width-20 )) | (y [I] >=( doc_height-20 ))){
MakeRain ();
Doc_width = document. body. clientWidth;
Doc_height = document. body. clientHeight ;}
Document. all ["dot" + I]. style. pixelTop = y [I];
Document. all ["dot" + I]. style. pixelLeft = x [I];}
SetTimeout ("raindropIE ()", speed );
}
Function updateRain (){
R [I] + = 10;
X [I] = r [I] * sn + cx [I];
Y [I] = r [I] * cs + cy [I];
}
Function makeRain (){
R [I] = 1;
Cx [I] = Math. random () * doc_width + 1;
Cy [I] = 1;
X [I] = r [I] * sn + cx [I];
Y [I] = r [I] * cs + cy [I];
}
RaindropIE ();
</Script>
</BODY>
</HTML>
I hope this article will help you design javascript programs.