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