<!DOCTYPE?html>
<meta?charset="utf-8">
<head>
<title></title>
<style?type="text/css">
#div1{width:?100px;height:?200px;background-color:?red;position:?absolute;?right:?0;bottom:?0;}
</style>
<script?type="text/javascript">
window.onscroll?=?function()
{
var?oDiv1?=?document.getElementById('div1');
var?scrollTop?=?document.documentElement.scrollTop||document.body.scrollTop;
startMove(document.documentElement.clientHeight-oDiv1.offsetHeight+scrollTop);
}
var?timer?=?null;
function?startMove(iTarget)
{
var?oDiv1?=?document.getElementById('div1');
clearInterval(timer);
timer?=?setInterval(function(){
var?speed?=?(iTarget-oDiv.offsetTop)/8;
speed?=?speed>0?Math.ceil(speed):Math.floor(speed);
if?(oDiv1.offsetTop==iTarget)?
{
clearInterval(timer);
}
else
{
oDiv1.style.top?=?oDiv1.offsetTop+speed+'px';
}
},30);
}
</script>
</head>
<body?style="height:?2000px;">
<div?id="div1"></div>
</body>
</html>
【已解決】這個javascript的右側(cè)懸浮框?yàn)槭裁礋o法實(shí)現(xiàn)?
簡若婷
2017-06-15 21:12:12