課程
/前端開發(fā)
/HTML/CSS
/回到頂部效果
老師講的時(shí)候有個(gè)地方說一直減小,到下面怎么又增大了?我看數(shù)值還是減小啊
2017-07-28
源自:回到頂部效果 4-1
正在回答
window.onload=function(){var obtn=document.getElementById("btn"),timer,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, ispeed=Math.floor(-osTop/6);isTop=true;document.documentElement.scrollTop=document.body.scrollTop=osTop+ispeed;if(osTop==0){clearInterval(timer);}},30); }};
多看幾遍,
舉報(bào)
回到頂部網(wǎng)站不可缺少的一部分,用JS實(shí)現(xiàn)炫酷拉風(fēng)的回到頂部效果
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-08-31
window.onload=function(){var obtn=document.getElementById("btn"),timer,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, ispeed=Math.floor(-osTop/6);isTop=true;document.documentElement.scrollTop=document.body.scrollTop=osTop+ispeed;if(osTop==0){clearInterval(timer);}},30); }};
2017-07-30
多看幾遍,