If there is a certain JavaScript foundation, it is easier to make floating advertisements. Code directly:
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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<Style type = "text/css">
*{
Margin: 0;
Padding: 0;
}
# Csdn
{
Width: 800px;
Margin: 0 auto;
}
# Ad
{
Position: absolute;
Right: 0px;
Top: 30px;
Z-index: 1;
}
# Cl
{
Position: absolute;
Right: 0px;
Top: 30px;
Z-index: 2;
}
</Style>
<Script type = "text/javascript">
Var advInitTop = 30;
Var closeInitTop = 30;
Function inix ()
{
AdvInitTop = document. getElementById ("ad"). style. pixelTop;
CloseInitTop = document. getElementById ("cl"). style. pixelTop;
}
Function closeAd ()
{
Document. getElementById ("ad"). style. display = "none ";
Document. getElementById ("cl"). style. display = "none ";
}
Function move ()
{
// Document. getElementById ("ad"). style. pixelTop = document. body. scrollTop + advInitTop;
// Document. getElementById ("cl"). style. pixelTop = document. body. scrollTop + closeInitTop;
Document. getElementById ("ad" ).style.pixelTop=document.doc umentElement. scrollTop + advInitTop;
Document. getElementById ("cl" ).style.pixelTop=document.doc umentElement. scrollTop + closeInitTop;
// Alert (document. getElementById ("ad"). style. pixelTop );
Registry.status+document.doc umentElement. scrollTop + "/" + document. getElementById ("ad"). style. pixelTop;
}
Window. onscroll = move;
</Script>
</Head>
<Body>
<Div id = "cl" onclick = "closeAd ()">
</Div>
<Div id = "csdn">
<A href = "http://www.csdn.net"> </a>
</Div>
<Div id = "ad">
<A href = "http://www.taobao.com"> </a>
</Div>
</Body>
</Html>
Key Points:
In the preceding code, use document.doc umentElement. Do not use the old document. body. Otherwise, it does not comply with w3c standards and cannot see the floating effect!