国产探花免费观看_亚洲丰满少妇自慰呻吟_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!");   } };
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍林郭勒市| 兴安盟| 武平县| 玉龙| 来安县| 蚌埠市| 湘潭县| 黄石市| 合阳县| 集安市| 北碚区| 凯里市| 屏东市| 英超| 丰原市| 佛坪县| 凌云县| 蕉岭县| 宣武区| 澄江县| 化德县| 漳平市| 泾阳县| 大安市| 阳新县| 吉首市| 乡城县| 新疆| 丹棱县| 宝山区| 波密县| 尉氏县| 七台河市| 那曲县| 吐鲁番市| 富民县| 南木林县| 东乌| 宣化县| 历史| 南木林县|