问题是这个:
https://zhidao.baidu.com/question/564452770.html
html
<div id="divMsgLeftInfo" class="right_bottom" style="top:700px;">
<div>
<img src="../../public/static/dian/img/index/xuanfu.png" alt="">
</div>
</div>
js
methods:{
heartBeatLeft(){
var diffYLeft=document.documentElement.scrollTop; //获得当前滚动条位置
if(diffYLeft<2040){
var percent=0.1*(diffYLeft-this.lastScrollYLeft);
if(percent>0)
percent=Math.ceil(percent); //浮点数向上取整.
else percent=Math.floor(percent); //浮点数向下取整
document.getElementById("divMsgLeftInfo").style.top
= parseInt(document.getElementById("divMsgLeftInfo").style.top)+percent+"px";
//滚动元素的top等于本身的高度取整+上/下的取整+‘px’
this.lastScrollYLeft=this.lastScrollYLeft+percent; //重新设置滚动后当前元素的高度,便于下次计算
}else{
console.log("超过这个距离了")
}
},
}
mounted:function(){
this.load();
//监听浏览器滚动条位置
window.addEventListener('scroll',window.setInterval(this.heartBeatLeft,10),false)
// window.addEventListener('scroll',this.heartBeatRight,false)
},