Cool floating code

Source: Internet
Author: User

Code:
Var no = 8;
Var oTime = new Date ();
Var lastTime = oTime. getTime ();
Var x_sin, x_point, y_point;
Var x_length, x_increased, y_increased;
Var I, body_width = 932, body_height = 538;
Var lastTime = 0;
Var fallInterval = 2.4;

X_sin = new Array ();
X_point = new Array ();
Y_point = new Array ();
X_length = new Array ();
X_increased = new Array ();
Y_increased = new Array ();
Var oBody = document. body;
Var d = document;

/* Body_width = oBody. clientWidth;
Body_height = oBody. clientHeight ;*/

For (I = 0; I <no; ++ I ){
SnowFlakeImgNo = Math. round (Math. random () * (snowflake. length-1 ));
X_sin [I] = 0;
X_point [I] = Math. random () * (body_width-250) + 100;
Y_point [I] = Math. random () * body_height;
X_length [I] = Math. random () * 20;
// X_increased [I] = 0.02 + Math. random ()/10;
// Y_increased [I] = 0.7 + Math. random ();
X_increased [I] = 0.08 + Math. random ()/5;
Y_increased [I] = 2.7 + Math. random () * 2;

D. write ("<div id = \" snowFlakeDiv _ "+ I +" \ "style = \" position: absolute; z-index: 11; visibility: visible; top: 15px; left: 215px; \ "> </ div> ");
}

Function snowFlakeFloat (){
Var now = new Date ();
Var second = now. getTime ();
Var scrollTop = document. body. scrollTop;
Var snowflakeDiv_0 = d. getElementById ("snowFlakeDiv_0 ");
Var snowflakeDiv_1 = d. getElementById ("snowFlakeDiv_1 ");
Var snowflakeDiv_2 = d. getElementById ("snowFlakeDiv_2 ");
Var snowflakeDiv_3 = d. getElementById ("snowFlakeDiv_3 ");
Var snowflakeDiv_4 = d. getElementById ("snowFlakeDiv_4 ");
Var snowflakeDiv_5 = d. getElementById ("snowFlakeDiv_5 ");
Var snowflakeDiv_6 = d. getElementById ("snowFlakeDiv_6 ");
Var snowflakeDiv_7 = d. getElementById ("snowFlakeDiv_7 ");
For (I = 0; I <no; I ++ ){
If (y_point [I]> = 0 ){
Y_point [I] + = y_increased [I];
}
If (y_point [I]> scrollTop + body_height-10 | y_point [I] <scrollTop | y_point [I] <0) {// remove the window or wait for the queue
If (second-lastTime)/1000> fallInterval) {// drops from the queue
SnowFlakeImgNo = Math. round (Math. random () * (snowflake. length-1 ));
If (document. getElementById ('snowimg _ '+ I )){
Document. getElementById ('snowimg _ '+ I). src = snowflake [snowFlakeImgNo];
}
X_point [I] = Math. random () * (body_width-x_length [I]-250) + 100;
Y_point [I] = scrollTop;
X_increased [I] = 0.05 + Math. random ()/2;
Y_increased [I] = 2.7 + Math. random ()/2;
// X_increased [I] = 0.05;
// Y_increased [I] = 2.7;
Body_width = oBody. clientWidth;
Body_height = oBody. clientHeight;
LastTime = second;
} Else {
Y_point [I] =-50;
}

}
X_sin [I] + = x_increased [I];

Eval ("snowflakeDiv _" + I). style. pixelTop = y_point [I];
Eval ("snowflakeDiv _" + I). style. pixelLeft = x_point [I] + x_length [I] * Math. sin (x_sin [I]);

}
}

Window. setInterval ("snowFlakeFloat ()", 100 );

2. link the code file on the page you need: <SCRIPT language = javascript src = "floating. js"> </SCRIPT>
3.
Add Images
Code:

Reference:
<SCRIPT language = JavaScript>
// I only added three images. In fact, you can add several more images. The image files are generally small.
Var snowflake = new Array ();
Snowflake [0] pai'float1.gif '; // image 1
Snowflake [1] pai'float2.gif '; // Image 2
Snowflake [2] pai'float3.gif '; // picture 3
</SCRIPT>

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.