6

And once it hits the bottom,then have a callback function?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

25

You can use .scroll() event in this way on your window:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert("bottom!");
   }
});

check live demo

to detect if the user is 3/4 down the page you can try this one

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - .75*$(document).height()) {
       alert("3/4th of bottom!");
   }
});
Andy Novocin
  • 454
  • 3
  • 14
Java
  • 2,451
  • 10
  • 48
  • 85
  • generally it works, but with "alert" it crashed my FF, it literally "blacked out". But I tested with console.log and it worked fine. – devnull69 Mar 14 '12 at 07:57
  • Thanks. THis works! What if I want to detect if the user is 3/4 down the page? – TIMEX Mar 14 '12 at 08:15
  • 7
    I think your solution for 3/4 down the page is actually looking for "75 pixels from the bottom of the page". Changing `$(document).height() - 75` to `$(document).height() * 0.75` should do the trick. – sffc Jul 25 '13 at 10:23
  • 1
    that live demo doesnt work for me... Chrome 44.0.2403.125 if it helps) – dtc Jul 31 '15 at 10:07
  • This works wonderfully for me everywhere but on my mobile. If I can figure out the issue, I'll post an update. – lysdexia Aug 05 '15 at 21:25
  • Addendum: nothing wrong on phone: I was testing a lazy-loading scroll function and didn't have enough data to trigger it on the server I was testing the mobile on. Works great! – lysdexia Aug 05 '15 at 21:49