DOM case --- classic imitation 163 homepage scaling Advertisement

Source: Internet
Author: User

<! 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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> ad shrinking effect on the 163 homepage </title>
<Style>
# Top {
Position: relative;
}
# Content {
Position: absolute;
}
 
</Style>
</Head>
<Body onload = "moveDown ()" style = "margin: 0px; 0px;">
<Div id = "top" style = "width: 100%; height: 100px; background-color: # F96"> webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
Webpage advertisement <br>
</Div>
<Div id = "content" style = "width: 100%; height: 500px; background-color: # FF9"> This is the body of the webpage </div>
</Body>
</Html>
<Script language = "javascript" type = "text/javascript">
// Define the distance to be moved
Var h = 0;
Var maxheight = 300;
Var st;
Var top = document. getElementById ("top ");
// Initially, set top to hidden.
Top. style. display = "none ";
// Define to expand the advertisement part
Function moveDown (){
// Accumulate
H + = 2;
// Set the height to the value we accumulate
Top. style. height = h;
// Set the layer display
Top. style. display = "block ";
// Determine whether the maximum value is reached
If (h <= maxheight ){
 
St = setTimeout ("moveDown ()", 50 );

} Else {
 
ClearTimeout (st );
// Delay 3 seconds and start to contract
SetTimeout ("moveUp ()", 3000 );
 
}

}
 
// Define to shrink the advertisement part
Function moveUp (){
// Set
H-= 2;
// Set the height to the value we accumulate
Top. style. height = h;
// Set the layer display
Top. style. display = "block ";

If (h <= 0 ){

Top. style. display = "none ";

// Clear the timer
ClearTimeout (st );

} Else {

// If h> 0, continue to contract
St = setTimeout ("moveUp ()", 50 );

}


}

 
</Script>


From the column by Liu haicao

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.