I need to detect if a user is scrolled to the bottom of a page. If they are at the bottom of the page, when I add new content to the bottom, I will automatically scroll them
The accepted answer did not work for me. This did:
const element = document.createElement('div');
document.body.appendChild(element);
document.addEventListener('scroll', () => {
const viewportHeight = window.innerHeight;
const distance = element.getBoundingClientRect().top;
if (Math.floor(distance) <= viewportHeight) {
console.log('yep')
} else {
console.log('nope')
}
})