Northernlights
Northernlights

Reputation: 109

Is there a way for JS to detect that the bottom of a div has been reached, rather than the bottom of a page?

I'm using this at the moment:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
      $(".initial").delay(2000).fadeOut("slow", function() {
          $(".secondary").fadeIn("slow");
      });
    }
});

And I've tried fiddling around with window and replacing it with div names and static pixel values for the scroll to no avail.

Upvotes: 0

Views: 79

Answers (1)

Arnaud Le Blanc
Arnaud Le Blanc

Reputation: 99879

Yes. Replace $(document).height() by ($(elem).offset().top+$(elem).outerHeight())

Upvotes: 1

Related Questions