javascript - Why can't I scroll the scroll bar again after changing speed to Math.round(speed)?
怪我咯
怪我咯 2017-05-19 10:45:44
0
1
831

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

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
小葫芦
var speed = 0.4;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
// speed = 1;
speed=Math.round(speed);
// speed = 0;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!