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

 

posted @ 2020-05-11 22:12  ladybug7  阅读(1033)  评论(2编辑  收藏  举报