-
整除需要考慮小數(shù)點(diǎn)查看全部
-
JS實現(xiàn)回到頂部效果的思路查看全部
-
需要用到的JavaScript的API查看全部
-
回到頂部:查看全部
-
-40px;因為定位在背景圖片的上半部,-40會移到此時背景圖片的下半部;+40會移動此時背景圖片的上方查看全部
-
ie和谷歌瀏覽器獲取到當(dāng)前滾動條數(shù)值查看全部
-
回到頂部效果查看全部
-
主要知識點(diǎn)查看全部
-
<span id="totop" >回到<br>頂部</span> <script> window.onload = function(){ var toTopButton = document.getElementById("totop"); var timer = null; //獲取可視區(qū)高度 var clientHeight = document.documentElement.clientHeight || document.body.clientHeight; //顯示隱藏按鈕 window.onscroll = function(){ var ostop = document.documentElement.scroolTop || document.body.scrollTop; if(ostop>=clientHeight){ toTopButton.style.display = "block"; } else{ toTopButton.style.display = "none"; } } //點(diǎn)擊回到頂部 toTopButton.onclick = function(){ timer = setInterval(function(){ var ostop = document.documentElement.scroolTop || document.body.scrollTop; var ispeed = Math.ceil(ostop/5); document.documentElement.scroolTop = document.body.scrollTop = ostop-ispeed; if(ostop == 0){ clearInterval(timer); } },20); } } </script>查看全部
-
123查看全部
-
document.documentElement.clientHeight - 獲取可視高度查看全部
-
Math.floor() - 向下舍入取整查看全部
-
IE:document.documentElement.scrollTop chrome: document.body.scrollTop;查看全部
-
<a href="javascript:;">button</a> - javascript:; 可以阻止瀏覽器的默認(rèn)行為查看全部
-
定時器: setInterval() - 設(shè)置定時器,需傳入2個參數(shù) clearInterval() - 關(guān)閉定時器,需傳入1個參數(shù)查看全部
舉報
0/150
提交
取消