日期:2014-05-16 浏览次数:20468 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function initDiv(){
moveLeftDiv();
moveRightDiv();
}
//获得滚动条滚动的像素
function getBodyScrollHeight(){
if(window.innerHeight){
return window.pageYOffset;
}
else if(document.documentElement&&document.documentElement.scrollTop){
return document.documentElement.scrollTop;
}
else if(document.body){
return document.body.scrollTop;
}
}
//移动左栏
function moveLeftDiv(){
var el = document.getElementById("left");
//得到滚动条滚动的距离
var pos= getBodyScrollHeight();
var y = 100;
//将左栏向下移动pos个像素
el.style.top=(y+pos)+"px";
//10ms后移动
setTimeout("moveLeftDiv();",10);
}
//移动右栏
function moveRightDiv(){
var el = document.getElementById("right");
//得到滚动条滚动的距离
var pos= getBodyScrollHeight();
var y = 100;
//将右栏向下移动pos个像素
el.style.top=(y+pos)+"px";
//10ms后移动
setTimeout("moveRightDiv();",10);
}
</script>
</head>
<body onload = "initDiv();">
<div id = "left" style="position:absolute;z-index:999;border:1px solid red;width:100px;height:300px;top:100px;left:20px">
</div>
<div id="center" style="margin:0 200px;height:8000px;background:#ccc;">
<a>124</a>
</div>
<div id="right" style="position:absolute;z-index:999;border:1px solid red;width:100px;height:300px;top:100px;right:20px">
</div>
</body>
</html>