How to create website page where content will load automatically after every page scroll?


We can achieve this by using "scroll" event listener where callback function checks if scroll position is near the end of the page then it will load more content. Below is the code snippet:

    .container>div {
        min-height: 40px;
    <div class="container">
        window.addEventListener("scroll", function () {
            var el = document.querySelector(".container");
            if (el.scrollTop + el.offsetHeight > el.scrollHeight - 300) {
                console.log("Load more...")


Related #tags:     #html     #css     #javascript     #function    

Related questions

Looking for change? Click below to prepare for technical interview.

Technical Interview Questions