有不对的希望大家多多指教,哈哈哈
思路:
采用 监听防抖监听拉条的位置+自己实现分页的思路来实现的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div class="one" id="more"></div>
<script src="jquery-1.12.2.js"></script>
<script>
let page=1,limit=200,list=100000;
$(function(){
add()
})
window.onscroll = debounce(showTop,300)
function debounce(fn,delay){
let timer = null //借助闭包
return function() {
if(timer){
clearTimeout(timer)
}
timer = setTimeout(fn,delay) // 简化写法
}
}
function showTop() {
// 变量 scrollHeight 是滚动条的总高度
let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
// 变量 windowHeight 是可视区的高度
let windowHeight = document.documentElement.clientHeight || document.body.clientHeight
// 变量scrollTop为当前页面的滚动条纵坐标位置
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop
// 滚动条到底部得距离 = 滚动条的总高度 - 可视区的高度 - 当前页面的滚动条纵坐标位置
var scrollBottom = scrollHeight - windowHeight - scrollTop
console.log(scrollBottom,'scrollBottom')
if(scrollBottom==0){
page+=1;
add()
}
}
function add(){
console.log(page)
let num=(page-1)*200
for (let i = num; i < page*limit; i++) {
$('#more').append('<div>我是第'+i+'行</div>')
}
}
</script>
</body>
</html>