jQuery簡單的上拉加載


$(window).scroll(function() {
      var scrollTop = $(this).scrollTop(); //滾動條距離頂部的高度
      var scrollHeight = $(document).height(); //當前頁面的總高度
      var clientHeight = $(this).height(); //當前可視的頁面高度
      if (scrollTop + clientHeight >= scrollHeight - 50) {
         getData(); // 請求數據
      }
})  


window.onscroll = function() {
  //獲取被卷去高度
  var scrollTop = document.body.scrollTop;
  //獲取窗口高度(可見區域高度)
  var windowHeight = document.documentElement.clientHeight;
  //獲取文檔高度
  var documentHeight = document.body.scrollHeight;
  if (scrollTop + windowHeight >= documentHeight - 50) {
    $('#nomore').show();
  //發送Ajax請求獲取分頁數據
  }
}

 

 

/**
 * 得到瀏覽器顯示的屏幕高度
 */  
function getViewHeight() {
    if (window.innerHeight != window.undefined)
        return window.innerHeight;
    if (document.compatMode == 'CSS1Compat')
        return document.documentElement.clientHeight;
    if (document.body)
        return document.body.clientHeight;
    return window.undefined;
}

/**
 * 得到瀏覽器顯示的屏幕寬度
 */
function getViewWidth() {
    if (window.innerWidth != window.undefined)
        return window.innerWidth;
    if (document.compatMode == 'CSS1Compat')
        return document.documentElement.clientWidth;
    if (document.body)
        return document.body.clientWidth;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM