116
rated 0 times
[
117]
[
1]
/ answers: 1 / hits: 19711
/ 10 Years ago, fri, may 30, 2014, 12:00:00
I am trying to create an infinite loading page with the use of javascript. I found this: How to do infinite scrolling with javascript only without jquery
I have been playing with the last answer that links to this jsfiddle page: 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();
How would I modify that in order to make the scrolling work inside a div rather than as the whole page? As in, what would lastDivOffset and pageoffset change to?
More From » jquery