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

首頁 > 編程 > JavaScript > 正文

基于javascript實現瀏覽器滾動條快到底部時自動加載數據

2019-11-20 11:07:09
字體:
來源:轉載
供稿:網友

廢話不多說了,直接給大家貼js代碼了。

 <!DOCTYPE html> <html> <head>   <script src="jquery-...js" type="text/javascript"></script>   <script type="text/javascript">     $(document).ready(function () {       var range = ;       //距下邊界長度/單位px       var elemt = ;       //插入元素高度/單位px       var maxnum = ;      //設置加載最多次數       var num = ;       var totalheight = ;       var main = $("#content");           //主體元素       $(window).scroll(function () {         var srollPos = $(window).scrollTop();  //滾動條距頂部距離(頁面超出窗口的高度)         //console.log("滾動條到頂部的垂直高度: "+$(document).scrollTop());         //console.log("頁面的文檔高度 :"+$(document).height());         //console.log('瀏覽器的高度:'+$(window).height());         totalheight = parseFloat($(window).height()) + parseFloat(srollPos);//滾動條當前位置距頂部距離+瀏覽器的高度         if (($(document).height() - totalheight) <= range && num != maxnum) {//頁面底部與滾動條底部的距離<range           main.append("<div style='border:px solid tomato;margin-top:px;color:#ac" + (num % ) + (num % ) + ";height:" + elemt + "' >hello world" + srollPos + "---" + num + "</div>");           main.append("<div style='border:px solid tomato;margin-top:px;color:#ac" + (num % ) + (num % ) + ";height:" + elemt + "' >hello world" + srollPos + "---" + num + "</div>");           num++;         }       });     });   </script> </head> <body>   <div id="content" style="height:px">     <div id="follow">this is a scroll test;<br />  頁面下拉自動加載內容</div>     <div style='border:px solid tomato;margin-top:px;color:#ac;height:'>hello world test DIV</div>   </div> </body> </html>

ps:原生JavaScript如何觸發滾動條事件?

<script>window.onscroll = function(){var scrollT = document.documentElement.scrollTop||document.body.scrollTop;var scrollH = document.documentElement.scrollHeight||document.body.scrollHeight;var clientH = document.documentElement.clientHeight||document.body.clientHeight//console.log(scrollT +"+"+scrollH+"+"+clientH);if(scrollT == scrollH - clientH){console.log("到底部了");}else if(scrollT == 0){console.log("到頂部了");}}</script>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 益阳市| 湖州市| 镇平县| 阜宁县| 临潭县| 宝鸡市| 永济市| 汉川市| 安新县| 中牟县| 三明市| 海丰县| 新营市| 抚顺县| 慈溪市| 新宾| 交口县| 福鼎市| 乌恰县| 灵石县| 格尔木市| 湘阴县| 锡林浩特市| 瑞安市| 仁布县| 渝北区| 玉山县| 酒泉市| 涞源县| 邵东县| 石泉县| 宁国市| 资溪县| 平陆县| 临猗县| 弥勒县| 海门市| 阿瓦提县| 资溪县| 株洲市| 永川市|