<div ref="rightDiv">11233</div>
mounted(){
this.$refs.rightDiv.addEventListener('scroll',this.scroll)
// debounce 是一个防抖工具类函数 需要自己定义
}
scroll() {
const scrollTop = this.$refs.rightDiv.scrollTop
// 获取可视区的高度
const windowHeight = this.$refs.rightDiv.clientHeight
// 获取滚动条的总高度
const scrollHeight = this.$refs.rightDiv.scrollHeight
console.log(
'scrollTop',
scrollTop,
'windowHeight',
windowHeight,
'scrollHeight',
scrollHeight
)
if (scrollTop + windowHeight >= scrollHeight ) {
// 把距离顶部的距离加上可视区域的高度 等于或者大于滚动条的总高度就是到达底部
// 调用函数
}
},
vue中监听div的滑动到底部 ,并实现懒加载
最新推荐文章于 2024-03-09 17:01:46 发布