仿osc推荐浮动条(demo)

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
#a1 {
	height: 150px;
	width: 1000px;
	background: #aaa;
}
#a2 {
	height: 50px;
	width: 1000px;
	background:#ab9;
	z-index:999;
	top:0px;
}
#a3 {
	height: 1720px;
	width: 1000px;
	background:#fb9;
}
</style>
<script type="text/javascript">

function flo(){
var p=document.body.scrollTop;
var i=document.getElementById("a2");
document.getElementById("a3").innerHTML=p;
if(p>=document.getElementById("a22").offsetTop){
	i.style.position="fixed";
	
}else{
	i.style.position="static";
}

}
setInterval(flo,1);
</script>
</head>
<body>
<div id="a1">这是第一个div</div>
<div id="a22"></div>
<div id="a2">这是需要浮动的div</div>
<div id="a3" onMouseOver="flo();">这是用来占位的div </div>
</body>
</html>

本来可以用absolute定位的,但是因为函数刷新频率问题,推荐条总是会抖动。

还有一个问题就是js怎么控制fixed的top属性呢?依旧没有用jquery。。。。

你可能感兴趣的:(滚动条,相对浏览器窗口)