<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
</style>
<script type="text/javascript">
window.onscroll = move;//当移动滚动的时候触发
var y;//保存初始的y值
/*在文档加载后将广告图片的y值传到全局变量吗*/
function init(){
y = parseInt(document.getElementById("guangao").style.top);
}
/* 滚动页面要触发的函数 */
function move(){
//改变图片div的高度为初始高度加上滚动的高度;
var t= parseInt(document.body.scrollTop);
var s = y + t;
document.getElementById("guangao").style.top = s;
}
</script>
<title>无标题文档</title>
</head>
<body onLoad="init()">
<div>
</div>
<div id="guangao" style="width:200px;
height:200px;
margin-top:20px;
margin-left:30px;
border:1px solid red;
position:absolute;/*浮动层的绝对定位*/
left:12px;
top:20px;
z-index:1;/*在第一层*/ ">
<img src="../image/蜗牛.jpg" style="width:200px;
height:200px; ">
</div>
</body>
</html>
注意:头文件要去除