How to execute a function when user scroll past some some mark. say 100px above the page bottom
This is what I got
const onScroll = (e) => {
let scrollHeight, totalHeight
scrollHeight = document.body.scrollHeight
totalHeight = window.scrollY + window.innerHeight
if (totalHeight >= scrollHeight) {
// do stuff
}
}
const DetectScrollBottom = () => {
useEffect(() => {
window.addEventListener('scroll', onScroll, false)
return () => window.removeEventListener('scroll', onScroll, false)
}, [])
return <div></div>
}
Problem is, this executes function A at when scroll reaches bottom. not 100px above bottom.