JQ-滾動條下拉無限的加載數據
阿新 • • 發佈:2017-12-13
範圍 on() wid log body class scrollto idt 下拉
一、原理
利用滾動的高度,如果滾動的高度到達一定範圍,就加載數據
二、實現
利用$(document.body).outerWidth()獲取的是屏幕的高度,這個是固定的,不變的
利用$(window).scrollTop()獲取您滾動的高度
利用$(document).height()獲取總的高度
註:$(widnow).height()這個是可視區的高度,這個跟$(document).height()很容易混淆
三、上代碼
<section>
<div id="tishi">
<p>this is a scroll test;</p>
<p>頁面下拉自動加載內容</p>
</div>
<div id="main">
<p>hello world test DIV</p>
</div>
</section>
$(function(){
$(window).scroll(function(){
if($(window).scrollTop() > $(document.body).outerWidth() - $(‘#tishi‘).height()){
var s=‘<p class="load">我可以無限制的加載...</p>‘;
$(‘#main‘).append(s);
}
})
})
JQ-滾動條下拉無限的加載數據