I'm facing a challenge with my dynamic website that has numerous blog posts. My goal is to initially load only four posts and then add another four as the user scrolls to the end of the page. While I have figured out how to handle this on the backend, I am encountering issues on the frontend. Setting the height of html and body to 100% prevents scroll events on the window from working properly. To work around this, I decided to use a single div element to detect scrolling. Adding a scroll event listener to the div worked well, but I ran into trouble when trying to determine if the end of the scroll had been reached. The code I used was:
if (element.scrollHeight - element.scrollTop === element.clientHeight){
alert("End");
}
How can I ensure that the alert only appears once the div has been scrolled to the end, rather than at the beginning of the page load?