0

I am trying to implement an endless scroll functionality to my website and it is not working for some reason; This is the code I have

<script>
  $(document).ready(function () {
    alert("This part works");
    $(window).scroll(function () {
       if ($(window).scrollTop() == $(document).height()- $(window).height()) {
         alert("You have reached the bottom");
       }
    });
  });
</script>

The first alert box works and that lets me know that Jquery is working and the 2nd alert box is not working when i scroll to the bottom or at all any suggestions?

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
user1591668
  • 2,591
  • 5
  • 41
  • 84

1 Answers1

0

Try this:

   $(window).scroll(function (e) {
       var elem = $(e.currentTarget);
           if (elem[0].scrollHeight - elem.scrollTop() <= elem.outerHeight()) 
           {
               alert('You have reached the bottom')
           }
    });
mohammad falahat
  • 757
  • 1
  • 4
  • 11