分类:
架构
js实现当快滚动到底部时刷新数据
$(window).scroll(function () { var scrollTop = $(this).scrollTop(); var windowHeight = document.body.clientHeight; var scrollHeight = $(document).height(); console.log(scrollTop); console.log(windowHeight); console.log(scrollHeight); console.log("----------------------------"); if (scrollTop + windowHeight + 186 >= scrollHeight) { if (isdo) { isdo = false; getResourceOthers(); } } }); var page = 1; //防止滚动事件连续执行,在数据没有返回解析成功之前就不让他触发再次去请求后台了 var isdo = true; var getResourceOthers = function () { console.log('到底了请求一次数据'); //发送ajax,获取数据 $.post('/x/j', function () { page++; isdo = true; }); }
要注意获取页面可视度高度的坑:
https://www.tnblog.net/aojiancc6/article/details/4043
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
评价