- 监控滚动,计算高度差
lisent() {
let listBoxDom = document.getElementsByClassName('list')[0]
listBoxDom.addEventListener('scroll', () => {
let listBoxDom = document.getElementsByClassName('list')[0]
let listBoxHeight = listBoxDom.clientHeight;
let lastChildDom = listBoxDom.lastChild
let lastChildHeight = lastChildDom.clientHeight
if (lastChildDom.offsetTop - listBoxDom.scrollTop <= (listBoxHeight - lastChildHeight)) {
// 子元素顶部到整个滚动区域的顶部距离-父元素垂直滚动的距离 <= 父元素可视高度-子元素的高度
// 获取元素加入列表中
this.getData()
}
})
},