I'm currently working on implementing an infinite loading feature using JavaScript. I came across this helpful resource that explains how to achieve infinite scrolling without jQuery: How to do infinite scrolling with javascript only without jquery
After some experimentation, I've been focusing on the last answer provided in the thread which links to a jsfiddle demo: http://jsfiddle.net/8LpFR/
document.addEventListener("scroll", function (event) {
checkForNewDiv();
});
var checkForNewDiv = function () {
var lastDiv = document.querySelector("#scroll-content > div:last-child");
var lastDivOffset = lastDiv.offsetTop + lastDiv.clientHeight;
var pageOffset = window.pageYOffset + window.innerHeight;
if (pageOffset > lastDivOffset - 10) {
var newDiv = document.createElement("div");
newDiv.innerHTML = "my awesome new div";
document.getElementById("scroll-content").appendChild(newDiv);
checkForNewDiv();
}
};
checkForNewDiv();
I'm now looking into adapting this code to enable scrolling within a specific div rather than the entire page. What changes would need to be made to the lastDivOffset and pageOffset variables for this modification?