Javascript is compatible with IE7 or later versions and FF

Source: Internet
Author: User

Clip first:

Background image:

Floating cloud image: yun---------- here is the image D ~ You can see all the options (because the background is white and the cloud is white ~)......
CSS code:

Copy codeThe Code is as follows: <style type = "text/css">
*
{
Margin: 0;
Padding: 0;
}
Body
{
Background: url ("Images/body_bg.jpg") repeat center 0 fixed;
}
. Cloud
{
Background: url ("Images/cloud1.png ");
Height: 250px;
Width: 580px;
Position: absolute;
}
. HScroll
{
Overflow: hidden;
}
</Style>

Understanding:. hScroll is used to hide the browser's scroll bar; others can see what is going on, and I will not talk nonsense;
Code in body:Copy codeThe Code is as follows: <body onload = "StartMove ()">
<Div class = "cloud" id = "moveCloud">
</Div>
</Body>

Understanding: Call the StarMove () function during page loading;
Javascript code:Copy codeThe Code is as follows: <script language = "javascript" type = "text/javascript">
Var cloud = null;
Var left = 0;
Document.doc umentElement. className = "hScroll ";
Function StartMove (){
Cloud = document. getElementById ("moveCloud ");
SetInterval (Move, 100 );
}
Function Move (){
Left + = 1;
Cloud. style. left = left + "px ";
If (left> = (screen. width )){
Left =-580;
}
}
</Script>

Understanding: document.doc umentElement. className = "hScroll"; is to call the code in the css style to hide the browser's scroll bar (nonsense ...... I have not said it above ^ _ ^ |)
First, we need to obtain the id of the "floating cloud" layer, so we use cloud = document. getElementById ("moveCloud"); cloud is a global variable that has been defined above, so it can be used directly here (for new birds, Do not spray it ).
Then, give him another "timer" setInterval (Move, 100); call the Move function once every 100 milliseconds;
Left + = 1; equivalent to left = left + 1; used with the above function (called every 100 milliseconds ~) And then assigned the original coordinates to the "floating cloud" layer. Therefore, it is written as cloud. style. left = left + "px ";
Shenma? What is left? This is the position attribute in css styles! I don't believe you have written a position colon in DW. Why don't you see it?
If (left> = (screen. width); left =-580; that is, if the position of "floating cloud" is greater than or equal to the width of the screen, let him start from scratch, set the left value to-580;
Why set-580 ?? Look at the CSS. The size of the floating cloud image is 580*250, that is, its length is 580 PX. Therefore, it is set to-to make it display a little bit from the right, otherwise, the whole picture will be displayed as soon as it comes up. how scary it is ~
I have never heard of it for half a day, and I have no idea about it. The next page is the sample code, which should be a. html file. Download the image yourself and don't forget to change the path!
Complete code:Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Move background images </title>
<Style type = "text/css">
*
{
Margin: 0;
Padding: 0;
}
Body
{
Background: url ("Images/body_bg.jpg") repeat center 0 fixed;
}
. Cloud
{
Background: url ("Images/cloud1.png ");
Height: 250px;
Width: 580px;
Position: absolute;
}
. HScroll
{
Overflow: hidden;
}
</Style>
<Script language = "javascript" type = "text/javascript">
Var cloud = null;
Var left = 0;
Document.doc umentElement. className = "hScroll ";
Function StartMove (){
Cloud = document. getElementById ("moveCloud ");
SetInterval (Move, 100 );
}
Function Move (){
Left + = 1;
Cloud. style. left = left + "px ";
If (left> = (screen. width )){
Left =-580;
}
}
</Script>
</Head>
<Body onload = "StartMove ()">
<Div class = "cloud" id = "moveCloud">
</Div>
</Body>
</Html>

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.