<script> window.onload=function(){ var oBtn = document.getElementById(‘btn‘); var turn =false ; var time = null ; window.onscroll=function(){ if(turn){ clearInterval(time) } turn =true ; } oBtn.onclick=function () { time= setInterval(function(){ // document.body.scrollTop谷歌浏览器支持 document.documentElement.scrollTopIE以及火狐支持 var scroll=document.documentElement.scrollTop||document.body.scrollTop ; var spend =Math.floor( -scroll/20 ) ; if(scroll==0){ clearInterval(time) } document.documentElement.scrollTop=document.body.scrollTop=scroll+spend; turn =false; },30) } } </script>
时间: 2024-10-19 04:25:44