当前位置:   article > 正文

html中右边跟随移动的悬浮窗口,JS实现右侧悬浮框随着页面的上下轮动而移动

html 右边跟随滚动条上下移动
Document

#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)

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/76902
推荐阅读
相关标签
  

闽ICP备14008679号