<script type="text/javascript"> window.onload=function(){ var obtn=document.getElementById('btn'); var timer=null; var isTop=true;// 滾動條滾動時觸發? ? ? ? ? ? window.onscroll=function(){? ? ? ? ? ? if(!isTop){? ? ? ? ? ? clearInterval(timer);? ? ? ? ? ? }? ? ? ? ? ? isTop=false;? ? ? ? ? ? } obtn.onclick=function(){// 設置定時器 timer=setInterval(function(){// 獲取滾動條距離頂部的高度? ? ? ? ? ? ? ? ?? var osTop=document.documentElement.scrollTop || document.body.scrollTop; var ispeed= Math.floor(-ispeed / 6); document.documentElement.scrollTop=document.body.scrollTop =osTop+ispeed;? ? ? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? isTop=true; if(osTop==0){ clearInterval(timer); } },30); } ?// document.documentElement.scrollTop ?谷歌瀏覽器不兼容 ? ?document.body.scrollTop;兼容谷歌瀏覽器 } </script>
高手們幫忙看一下,哪里寫錯了,感覺效果跟老師有點區別,不知道哪里寫錯了
qq_不再犯錯_0
2016-08-07 23:38:43