Reputation: 876
Here is the logic of infinite scroll from the top to the bottom of the screen :
height = function (elem) {
elem = elem[0] || elem;
if (isNaN(elem.offsetHeight)) {
return elem.document.documentElement.clientHeight;
} else {
return elem.offsetHeight;
}
};
offsetTop = function (elem) {
if (!elem[0].getBoundingClientRect || elem.css('none')) {
return;
}
return elem[0].getBoundingClientRect().top + pageYOffset(elem);
};
pageYOffset = function (elem) {
elem = elem[0] || elem;
if (isNaN(window.pageYOffset)) {
return elem.document.documentElement.scrollTop;
} else {
return elem.ownerDocument.defaultView.pageYOffset;
}
}
handler = function () {
if (container === windowElement) {
containerBottom = height(container) + pageYOffset(container[0].document.documentElement);
console.log('height(elem', height(elem))
elementBottom = offsetTop(elem) + height(elem);
} else {
containerBottom = height(container);
containerTopOffset = 0;
if (offsetTop(container) !== void 0) {
containerTopOffset = offsetTop(container);
}
elementBottom = offsetTop(elem) - containerTopOffset + height(elem);
}
if (useDocumentBottom) {
elementBottom = height((elem[0].ownerDocument || elem[0].document).documentElement);
}
remaining = elementBottom - containerBottom;
shouldScroll = remaining <= height(container) * scrollDistance + 1;
}
How can I modify my code in order to infinite scroll properly from the bottom to the top of the screen.
I try to do this, i change the hendler function i remove all my code and I do this
elemenTop = pageYOffset(container[0].document.documentElement)
remaining = elemenTop - 250;
shouldScroll = remaining <= height(container) * scrollDistance + 1;
When u test infinite scroll module. if u want to use the scroll bar to go directly to the bottom of the screen it keeps loading the data till u have no data to load.With my modification when I go straight to the top of the screen with the scroll bar it doesn't keep loading my data, it stops to load the data and i have to scroll to make it work again.
I shouldn't have to scroll to make it work again when i'm in the top it should scroll itself since I have all the data loaded
Upvotes: 0
Views: 108