您的位置:首页 > Web前端 > JavaScript

js实现浮动框【缓冲效果】

2014-06-30 20:56 190 查看
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>右侧缓动悬浮宽</title>
<style type="text/css">
#f_fix{width: 100px;height: 150px;background: #808080;position: absolute;right: 0;}
</style>

</head>
<body style="height:2000px;">
<div id="f_fix"></div>

<script type="text/javascript">
window.onscroll=function()
{

var oDiv=document.getElementById('f_fix');
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
startMove(document.documentElement.clientHeight-oDiv.offsetHeight*1.5+scrollTop);

};

var timer=null;
function startMove(iTarget)
{
clearInterval(timer);
timer=setInterval(
function(){
var oDiv=document.getElementById('f_fix');
var speed=(iTarget-oDiv.offsetTop)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if (oDiv.offsetTop==iTarget) {
clearInterval(timer);
}else
{
oDiv.style.top=oDiv.offsetTop+speed+'px';
}
},30);
}

</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息