$(window).scroll(function () {
let clientHeight = document.documentElement.clientHeight; //浏览器高度
let scrollHeight = document.body.scrollHeight;
let scrollTop = document.documentElement.scrollTop;
let distance = 50; //距离视窗还用50的时候,开始触发;
if ((scrollTop + clientHeight) >= (scrollHeight - distance)) {
console.log('触发加载')
console.log(stopPage)
if (stopPage == true) {
return;
} else {
pageNo += 1
console.log("------------------执行了加载")
init()
stopPage = true
}
}
});
不是直接return了吗?你是不想再执行(scrollTop + clientHeight) >= (scrollHeight - distance)这个判断吗
就像这样,滑到底部的时候一直触发加载,导致我不停的请求数据
将let distance = 50;的值设置的大一些,比如200,看下还会一直加载么
说明 判断 不对