頁(yè)面自動(dòng)滾動(dòng)到底部

function getScrollTop(){

  var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;

  if(document.body){

    bodyScrollTop = document.body.scrollTop;

  }

  if(document.documentElement){

    documentScrollTop = document.documentElement.scrollTop;

  }

  scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;

  return scrollTop;

}

//文檔的總高度

function getScrollHeight(){

  var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;

  if(document.body){

    bodyScrollHeight = document.body.scrollHeight;

  }

  if(document.documentElement){

    documentScrollHeight = document.documentElement.scrollHeight;

  }

  scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;

  return scrollHeight;

}

//瀏覽器視口的高度

function getWindowHeight(){

  var windowHeight = 0;

  if(document.compatMode == "CSS1Compat"){

    windowHeight = document.documentElement.clientHeight;

  }else{

    windowHeight = document.body.clientHeight;

  }

  return windowHeight;

}

window.onscroll = function(){

//console.log(getScrollTop())

//console.log(getWindowHeight())

console.log(getScrollHeight())

  //if(getScrollTop() + getWindowHeight() == getScrollHeight()){

  //  alert("已經(jīng)到最底部了!!");

  //}

};

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些閱讀 2,144評(píng)論 0 2
  • Window和document對(duì)象的區(qū)別 window對(duì)象window對(duì)象表示瀏覽器中打開(kāi)的窗口window對(duì)象是...
    FConfidence閱讀 2,367評(píng)論 0 5
  • 100個(gè)常用的javascript函數(shù) 1、原生JavaScript實(shí)現(xiàn)字符串長(zhǎng)度截取 復(fù)制代碼代碼如下: fun...
    老頭子_d0ec閱讀 412評(píng)論 0 0
  • 找到fullcalendar.js, 找到代碼為 isRTL:false,這句話 輸入以下幾句 monthName...
    迷你小小白閱讀 1,863評(píng)論 0 1
  • 最近這些天睡覺(jué)前腦子里都是你,都是我們的曾經(jīng)。無(wú)論在做什么,腦子都會(huì)閃現(xiàn)出我們當(dāng)初在一起時(shí)的片段,我們互相表白的...
    我就是小布布閱讀 258評(píng)論 3 0

友情鏈接更多精彩內(nèi)容