document.documentElement.clientHeight為什么獲取的是對象的高度呢?
// JavaScript Document
//頁面加載完成后觸發
window.onload=function(){
?var obtn=document.getElementById("btn");
?//獲取頁面可視區的高度
?var clientHeight= document.documentElement.clientHeight;
?alert(clientHeight);
?var timer=null;
?var isTop=true;
??? //alert(clientHeight);
?//點擊按鈕用定時器監督
?obtn.onclick=function(){?
???? //設置定時器
???? timer=setInterval(function(){
???? //獲取滾動條離頂部的距離
??????? var osTop=document.documentElement.scrollTop||document.body.scrollTop;
???? //滾動條移動的速度
???? var ispeed=Math.floor(-osTop/5);
???? document.documentElement.scrollTop=document.body.scrollTop=osTop+ispeed;
???? isTop=true;
???? //清除定時器
??console.log(osTop-ispeed);
???? if(osTop==0){
???? clearInterval(timer);
????????????? }
???? },30);
?}
?
?//滾動條滾動時觸發
?window.onscroll=function(){
??var osTop=document.documentElement.scrollTop||document.body.scrollTop;
??if(osTop >= clientHeight){
???obtn.style.display='block';
??}else{
???obtn.style.display='none';
??}
??//在滾動的過程中可以手動操作滾動條
??if(!isTop){
???clearInterval(time);
???}
??isTop=false;
??}
? }
2018-03-23