这里感觉好奇怪啊,我的为什么没有显示视频的效果
来源:11-5 LoadMore上划加载更多-根据DOM位置判断加载时机

Valar丶Morghulis
2023-10-09
const { run: tryLoadMore } = useDebounceFn(
() => {
const elem = containerRef.current
if (elem === null) return
const domRect = elem.getBoundingClientRect()
if (domRect === null) return
console.log(domRect.bottom, document.body.clientHeight)
if (domRect.bottom <= document.body.clientHeight) {
console.log('执行加载')
}
},
{ wait: 300 }
)
document.body.clientHeight
是整个文档的高度,文档肯定包含containerRef
元素
这就导致了domRect.bottom
必定是小于document.body.clientHeight
,怎么弄刷新页面都会执行,随便滚动都会执行,因为domRect.bottom
必定是小于document.body.clientHeight
,不知道为什么老师的代码可以做到划到底部触发事件
写回答
1回答
-
双越
2023-10-10
你看看一开始 elem 的 height 是多少,和 body.clientHeight 哪个大
062024-04-01
相似问题