jquery - detecting if the bottom of the div is touching the bottom of the browser window?

前端 未结 2 739
旧巷少年郎
旧巷少年郎 2020-12-31 11:22

Given a div on a page. how to detect when the div is scrolled to the position where it is at the bottom of the browser window... flush with the bottom of the browser window?

2条回答
  •  被撕碎了的回忆
    2020-12-31 11:42

    I don't think the above answer would work, since offset().top is the space between the div and the top of the document, and is not variable. This worked for me:

    var a = $("#mydiv").offset().top;
    var b = $("#mydiv").height();
    var c = $(window).height();
    var d = $(window).scrollTop();
    if ((c+d)>(a+b)) {
      //bottom of #mydiv has just become visible
    }
    

提交回复
热议问题