1 let time = setInterval(() => { 2 let scroll = document.documentElement.scrollTop || document.body.scrollTop;//解决scrollTop始终为零,尽此行代码 3 if (scroll <= 100) { 4 clearInterval(time); 5 } else { 6 if (scroll >= 200) { 7 document.documentElement.scrollTop = scroll -= Math.ceil( 8 scroll / 30 9 ); 10 document.body.scrollTop = scroll -= Math.ceil( 11 scroll / 30 12 ); 13 } else { 14 clearInterval(time); 15 } 16 } 17 }, 10);