几种浮动广告的制作
例子:制作浮动的广告图片
<head>
<title>制作浮动的广告图片</title>
<script
language="javascript"
type="text/javascript">
var advInitTop=0;//使层总置于顶端的初始值
function move()
{
window.document.getElementById("advLayer").style.top=advInitTop+window.document.body.scrollTop;
}
window.onscroll=move;//窗口的滚动事件,当页面滚动时调用move()函数
</script>
</head>
<body
>
<div
id="advLayer"
style="position:absolute;left:16px;top:129px;width:180px;height:230px; z-index:1;">
<img src="images/bt.jpg"
width="180"
height="230"/>
</div>
</body>
例子:带关闭按钮的浮动的广告图片
<head>
<title>制作浮动的广告图片</title>
<script
language="javascript"
type="text/javascript">
//使层总置于顶端的初始值
var advInitTop=0;
var closeInitTop=0;
//获取广告图片所在的层上边距的初始值
function inix()
{
advInitTop=parseInt(window.document.getElementById("advLayer").style.top);
closeInitTop=parseInt(window.document.getElementById("closeLayer").style.top);
}
//使用广告图片所在的层与滚动条同步移动
function move()
{
document.getElementById("advLayer").style.top=advInitTop+parseInt(window.document.body.scrollTop);
document.getElementById("closeLayer").style.top=closeInitTop+parseInt(window.document.body.scrollTop);
}
//隐藏advLaayer closeLayer 并不为被隐藏的对象保留其物理空间
function closeMe()
{
window.document.getElementById("closeLayer").style.display="none";
window.document.getElementById("advLayer").style.display="none";
}
//窗口的滚动事件,当页面滚动时调用move()函数
window.onscroll=move;
</script>
</head>
<body onload="inix()">
<div
id="advLayer"
style="position:absolute;left:16px;top:80px;width:302px;height:171px; z-index:1;">
<img alt="adv"
src="images/lady_0007.jpg"
width="302"
height="171"/>
</div>
<div
id="closeLayer"
onclick="closeMe()"style="position:absolute;left:214px;top:230px;width:27px;height:19px;z-index:2;">
<img alt="close"
src="images/close.gif"/>
</div>
[此贴子已经被作者于2015-03-27 15:32:38编辑过]