<script type="text/javascript">
<!--知识点一,跟随滚动条的图片广告======================================================================-->
var initTop = 100;//距离上边距离
var initLeft = 10;//距离左边距离<?思考,如果网页是居中显示,应获取中心div的左上角为基点进行设置>
function closel(){//关闭广告层,获得广告层的ID然后通过style.display=none来隐藏层。
var mscroll = document.getElementById("mscroll");
if (mscroll){
mscroll.style.display="none";
}
}
function move(){//移动跟随,通过 window.onscroll系统事件调用move函数使图片也跟着动。
var mscroll = document.getElementById("mscroll");
if (mscroll)
{
if (document.documentElement)//不同的浏览器设置不同,如果能够获得document.documentElement,那么就通过他的scrollTop属性获得当前图片位置
{
mscroll.style.pixelTop = document.documentElement.scrollTop+initTop; // 保持mscroll层的上方位置不变
mscroll.style.pixelLeft = document.documentElement.scrollLeft+initLeft; //保持mscroll层的左边位置不变
}else{//如果不能获得documentElement对象那么就通过body对象的scrollTop属性来获取当前位置
mscroll.style.pixelTop = document.body.scrollTop+initTop; // 保持mscroll层的上方位置不变
mscroll.style.pixelLeft = document.body.scrollLeft+initLeft; //保持mscroll层的左边位置不变
}
}
}
window.onscroll = move; //窗口的滚动事件,当页面滚动时调用move()函数
</script>
body层
<!--带关闭按扭的随鼠标上下滚动的图片层-->
<DIV align="right" style="position:absolute;left:10px;top:100px;width:109px;background-color:#CCCCCC;z-index:2;" id="mscroll"><IMG src="images/close.jpg"><BR><A href="javascript:closel();">关闭</A></DIV>