Home » Jquery » jquery – Storing what page I am currently are when scrolling to the bottom JAVASCRIPT

jquery – Storing what page I am currently are when scrolling to the bottom JAVASCRIPT

Posted by: admin February 22, 2020 Leave a comment

Questions:

Currently I detect when I am at the bottom of the page.
I have a input hidden on the html, and when you scroll to the bottom, the input gets +1, but, when you get to the bottom, it adds alot of numbers.

How I add only +1 and it doesn’t get alot of +1?

function finalPage() {
        $(window).scroll(function () {
            if ($(window).scrollTop() + $(window).height() > $(document).height() -500) {
                loadMore();
            }
        });
    }

var num = $("#page").val();
num++;
$("#page").val(num);
How to&Answer:

Try this:

function finalPage() {
  $(window).scroll(function () {
    if ($(window).scrollTop() + $(window).height() > $(document).height() -500) {
      loadMore();

      $("#page").val($("#page").val()+1);
    }
  });
}