欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery scroll事件實現(xiàn)監(jiān)控滾動條分頁示例

 更新時間:2014年04月04日 08:55:44   作者:  
這篇文章主要介紹了jQuery scroll事件實現(xiàn)監(jiān)控滾動條分頁簡單示例,使用ajax加載,同時介紹了(document).height()與$(window).height()的區(qū)別,需要的朋友可以參考下

scroll事件適用于window對象,但也可滾動iframe框架與CSS overflow屬性設(shè)置為scroll的元素。

復(fù)制代碼 代碼如下:

$(document).ready(function () { //本人習慣這樣寫了
    $(window).scroll(function () {
        //$(window).scrollTop()這個方法是當前滾動條滾動的距離
        //$(window).height()獲取當前窗體的高度
        //$(document).height()獲取當前文檔的高度
        var bot = 50; //bot是底部距離的高度
        if ((bot + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
           //當?shù)撞炕揪嚯x+滾動的高度〉=文檔的高度-窗體的高度時;
            //我們需要去異步加載數(shù)據(jù)了
            $.getJSON("url", { page: "2" }, function (str) { alert(str); });
        }
    });
});

注意:(window).height()和(document).height()的區(qū)別

jQuery(window).height()代表了當前可見區(qū)域的大小,而jQuery(document).height()則代表了整個文檔的高度,可視具體情況使用.

注意當瀏覽器窗口大小改變時(如最大化或拉大窗口后) jQuery(window).height() 隨之改變,但是jQuery(document).height()是不變的。

復(fù)制代碼 代碼如下:

$(document).scrollTop() 獲取垂直滾動的距離  即當前滾動的地方的窗口頂端到整個頁面頂端的距離
$(document).scrollLeft() 這是獲取水平滾動條的距離

要獲取頂端 只需要獲取到scrollTop()==0的時候  就是頂端了

要獲取底端 只要獲取scrollTop()>=$(document).height()-$(window).height()  就可以知道已經(jīng)滾動到底端了

復(fù)制代碼 代碼如下:

$(document).height()  //是獲取整個頁面的高度
$(window).height()  //是獲取當前 也就是你瀏覽器所能看到的頁面的那部分的高度  這個大小在你縮放瀏覽器窗口大小時 會改變 與document是不一樣的  根據(jù)英文應(yīng)該也能理解吧

自己做個實驗就知道了
復(fù)制代碼 代碼如下:

$(document).scroll(function(){
    $("#lb").text($(document).scrollTop());
})
<span id="lb" style="top:100px;left:100px;position:fixed;"></span><!--一個固定的span標記 滾動時方便查看-->

相關(guān)文章

最新評論