Meaning of $(window).scrollTop() == $(document).height() - $(window).height()

后端 未结 3 1242
醉酒成梦
醉酒成梦 2021-02-03 15:10

The following code is used to detect if a user has scrolled to the bottom of the page and it works.

if($(window).scrollTop() == $(document).height() - $(window).         


        
3条回答
  •  执念已碎
    2021-02-03 15:51

    $(window).scrollTop() is the location of the top of the window relative to the document. On the page I'm looking at right now, that's 1385 if I'm scrolled to the very bottom. $(document).height() is the height of the entire page (1991 for me). $(window).height() is the height of the window (viewport) (606 for me). This means that the position of the top of the viewport plus the height of the window is the position of bottom of the viewport. 1385 + 606 = 1991.

提交回复
热议问题