滚动加载分页 上拉分页

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)
})

猜你喜欢

转载自blog.csdn.net/gwdgwd123/article/details/84135796