setInterval踩坑记

在做项目是,回到顶部效果,自己写的代码如下:

 1 this.time=setInterval(()=>{
 2                 document.documentElement.scrollTop-=500;
 3             },20)
 4             setTimeout(()=>{
 5                 console.log(11);
 6                 if(document.documentElement.scrollTop<=0){
 7                     clearInterval(this.time);
 8                     this.time=null;
 9                 } 
10             },500)
原文地址:https://www.cnblogs.com/muzishijie/p/11321424.html