<script type="text/javascript"> window.onload=function(){ var obtn=document.getElementById('btn'); var timer=null; var isTop=true;// 滾動(dòng)條滾動(dòng)時(shí)觸發(fā)? ? ? ? ? ? window.onscroll=function(){? ? ? ? ? ? if(!isTop){? ? ? ? ? ? clearInterval(timer);? ? ? ? ? ? }? ? ? ? ? ? isTop=false;? ? ? ? ? ? } obtn.onclick=function(){// 設(shè)置定時(shí)器 timer=setInterval(function(){// 獲取滾動(dòng)條距離頂部的高度? ? ? ? ? ? ? ? ?? 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>
高手們幫忙看一下,哪里寫錯(cuò)了,感覺效果跟老師有點(diǎn)區(qū)別,不知道哪里寫錯(cuò)了
qq_不再犯錯(cuò)_0
2016-08-07 23:38:43