欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js实现滑动到页面底部自动加载更多功能

程序员文章站 2023-11-21 11:38:46
话不多说,请看代码: //滚动条到页面底部加载更多案例 $(window).scroll(function(){ var scrolltop = $(th...

话不多说,请看代码:

//滚动条到页面底部加载更多案例 
$(window).scroll(function(){
 var scrolltop = $(this).scrolltop();    //滚动条距离顶部的高度
 var scrollheight = $(document).height();   //当前页面的总高度
 var clientheight = $(this).height();    //当前可视的页面高度
 // console.log("top:"+scrolltop+",doc:"+scrollheight+",client:"+clientheight);
 if(scrolltop + clientheight >= scrollheight){   //距离顶部+当前高度 >=文档总高度 即代表滑动到底部 count++;         //每次滑动count加1
 filterdata(servicetypeid,industryid,cityid,count); //调用筛选方法,count为当前分页数
 }else if(scrolltop<=0){ 
 //滚动条距离顶部的高度小于等于0 todo
 //alert("下拉刷新,要在这调用啥方法?");
 }
});

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!