If there is a certain JavaScript foundation, it is easier to make floating advertisements. Code directly:
<! 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!