赞
踩
#div{
200px;
height: 100px;
background: red;
position: absolute;
right: 0;
bottom: 40%;
}
window.onscroll = function () {
var oDiv = document.getElementById('div');
var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
//oDiv.style.top = (document.documentElement.clientHeight-oDiv.offsetHeight)/2+scrollTop+'px';
startMove(parseInt((document.documentElement.clientHeight-oDiv.offsetHeight)/2+scrollTop));
};
var time = null;
function startMove(iTarget){
var oDiv = document.getElementById('div');
clearInterval(time);
time = setInterval(function(){
var speed = (iTarget-oDiv.offsetTop)/6;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(oDiv.offsetTop == iTarget){
clearInterval(time)
}else{
oDiv.style.top = oDiv.offsetTop+speed+'px';
}
},30)
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。