获取滚动到底的方法

$(window).scroll(function(){
  //判断是否滑动到页面底部
if($(window).scrollTop()== $(document).height() - $(window).height()){
// TODO 滑动到底部时可请求下一页的数据并加载,加载可使用append方法
}
});

 

2、获取滚动条到文档顶部的距离,上图scrollTop那段。原生JS可用document.documentElement.scrollTop获取。

var scrollTop = Math.ceil($(this).scrollTop());
1
3、获取可视区高度。原生JS可用document.documentElement.clientHeight获取。

var _height = $(this).height()
1
4、获取文档总高度。原生JS用document.body.scrollHeight获取

var _h = $(document).height();
1
5、如果scrollTop+_height的距离大于等于_h,说明触底了,再次请求数据追加到当前数据后面即可。

posted @ 2019-08-27 10:24  yulong-nj  阅读(178)  评论(0)    收藏  举报