Implementation of Dynamic background effects generated by JavaScript, javascript background

Source: Internet
Author: User

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.

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.