var top = document.getElementsByClassName("top")[0];
var timer = null;
top.onclick=function()
{
timer=setInterval(function () {
var cur=document.body.scrollTop;
var speed=(0-cur)/2;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
// speed=Math.round(speed);This sentence is a comment
if(cur==0){
clearInterval(timer);
}
else{
document.body.scrollTop=cur+speed;
}
},30)
};
}
is to change the speed from speed=speed>0?Math.ceil(speed):Math.floor(speed); to
speed=Math.round(speed); and then click the element to return When you reach the top of the page, you can return to the top of the page normally, but
when you scroll the mouse wheel, the scroll bar cannot move and keeps going up, and the page keeps flashing. Why is this? Just change the speed value, and the effect is gone
走同样的路,发现不同的人生