How to Make floating ad JavaScript to make floating ad code

Source: Internet
Author: User

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!

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.