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

前端 未结 2 758
旧巷少年郎
旧巷少年郎 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:51

    Check

    if (($("#yourdiv").offset().top + $("#yourdiv").height()) >= $(window).height()) {
    }
    

    The .offset() method allows us to retrieve the current position of an element relative to the document. Contrast this with .position(), which retrieves the current position relative to the offset parent.

    See a working demo

提交回复
热议问题