jqueryscrollbarscrollto

Trigger function when scrollbar touches a DIV bottom - jQuery


I have a div that is in the middle of the page, I need to trigger a function when the scrollbar gets 100px before the bottom of a DIV.

I'm using jQuery.enter image description here

I played with all the combinations using

$(window).scrollTop();
$(document).height()
$('div').height();

but I can't get there.

Thanks for any help.


Solution

  • You can use this. Works in jsfiddle

    $(window).scroll(function() {
       var divTop = $('#yourDivId').offset().top,
           divHeight = $('#yourDivId').outerHeight(),
           wHeight = $(window).height(),
           windowScrTp = $(this).scrollTop();
       if (windowScrTp > (divTop+divHeight-wHeight-100)){
            alert('reached');
       }
    });