国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

jQuery實現判斷_滾動條到底部

2019-11-02 15:46:48
字體:
來源:轉載
供稿:網友

  這篇文章主要介紹了jQuery實現判斷滾動條到底部的相關資料,需要的朋友可以參考下

  判斷滾動條到底部,需要用到DOM的

第一放映室[www.aikan.tv/special/diyifangyingshi/]
三個屬性值,即scrollTop、clientHeight、scrollHeight。

  scrollTop為滾動條在Y軸上的滾動距離。

  clientHeight為內容可視區域的高度。

  scrollHeight為內容可視區域的高度加上溢出(滾動)的距離。

  從這個三個屬性的介紹就可以看出來,滾動條到底部的條件即為scrollTop + clientHeight == scrollHeight。

  廢話不多少說,趕緊上代碼(兼容不同的瀏覽器)。

lazyload.js

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  //滾動條在Y軸上的滾動距離 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(){   if(getScrollTop() + getWindowHeight() == getScrollHeight()){     alert("you are in the bottom!");   } };
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福泉市| 丽水市| 昭通市| 南城县| 洛宁县| 南通市| 桑植县| 军事| 监利县| 武川县| 呈贡县| 洛隆县| 兰坪| 泊头市| 西城区| 顺义区| 保山市| 吉林省| 乌什县| 治县。| 邯郸市| 社旗县| 沙雅县| 海林市| 北碚区| 新营市| 嵊泗县| 贵州省| 彩票| 庆安县| 白山市| 横峰县| 兰考县| 炎陵县| 鄂尔多斯市| 射洪县| 潜山县| 平昌县| 固镇县| 武陟县| 台东市|