Paco Pinazo Guna
Paco Pinazo Guna

Reputation: 117

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

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);

Upvotes: 1

Views: 49

Answers (1)

Nikhil Gyan
Nikhil Gyan

Reputation: 682

Try this:

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

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

Upvotes: 1

Related Questions