1. 程式人生 > >滾動載入分頁 上拉分頁

滾動載入分頁 上拉分頁

function scrollTop () {
  return Math.max(
    // chrome
    document.body.scrollTop,
    // firefox/IE
    document.documentElement.scrollTop)
}

function documentHeight () {
  // 現代瀏覽器(IE9+和其他瀏覽器)和IE8的document.body.scrollHeight和document.documentElement.scrollHeight都可以
  return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
}

function windowHeight () {
  return (document.compatMode == 'CSS1Compat')
    ? document.documentElement.clientHeight
    : document.body.clientHeight
}
// 上拉載入更多
var winH = $(window).height()
var checkTimer
$(document).scroll(function () {
  clearTimeout(checkTimer)
  checkTimer = setTimeout(function () {
    if (scrollTop() + windowHeight() >= (documentHeight() - 50)) {
      // 滾動分頁ajax請求寫在裡面
    }
  }, 200)
})