I have api of listings that returns me data page wise. I have implemented infinite scolling for the listings.
What I am currently using to do is:
if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
console.log("Scroll Postion" + $(window).scrollTop());
//API HIT
}
This works like a charm but the problem is that user has to scroll till the absolute bottom of the page to hit api.
What we want to achieve is - when user is at 75% to 80% from the top of the page, api hit for next page should automatically go.
I tried using:
if ($(window).scrollTop() * 1.2 >= $(document).height() - $(window).height())
AND
if ($(window).scrollTop() + 100 >= $(document).height() - $(window).height())
But both of the approaches are hitting multiple api when we scroll to bottom of the page.
Any better solution for this?