<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
#div1{ top:10px;}
</style>
</head>
<body>
<div id="div1" style="position:absolute; background-color:#0FF; width:200px; top:0px; height:400px;"><!--代替广告的div盒子-->
</div>
<script type="text/javascript">
function move()
{
if(parseInt(document.documentElement.scrollTop)=='')//兼容性
var RealTop=parseInt(document.body.scrollTop); //除了ie 和 firefox 浏览器其他的使用这个
else
var RealTop=parseInt(document.documentElement.scrollTop);//ieie 和 firefox
var left=0;
left+=RealTop;
div1.style.top=left+'px';
}
setInterval("move()",1);//每0.1秒执行move函数
</script>
sdkjj<br><!--为了增加页面长度而设-->
sdkjj<br>
sdkjj<br>sdkjj<br>vsdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>
sdkjj<br>
sdkjj<br>
sdkjj<br>sdkjj<br>vsdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>
sdkjj<br>sdkjj<br>vsdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>
sdkjj<br>
sdkjj<br>
sdkjj<br>sdkjj<br>vsdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>sdkjj<br>
</body>
</html>
1.(在ie和firefox中) html不指定文档类型获取scroll函数时可以使用document.body.scrollTop,但指定后必须使用document.documentElement.scrollTop。(在其他浏览器中)可以随意使用document.body.scrollTop,但使用document.documentElement.scrollTop无效
2.不写<!doctype html> ,也就是指定文档类型或者在style标签中在属性值前把:写成=,会导致js获取style值时全部是空值
这只是我写悬浮广告时,遇到的 一些困难而已,不足之处,多多指教.