[removed] How to detect if browser window is scrolled to bottom?

后端 未结 19 1258
你的背包
你的背包 2020-11-22 16:00

I need to detect if a user is scrolled to the bottom of a page. If they are at the bottom of the page, when I add new content to the bottom, I will automatically scroll them

19条回答
  •  深忆病人
    2020-11-22 16:23

    The accepted answer did not work for me. This did:

    window.onscroll = function(ev) {
        if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
          // you're at the bottom of the page
          console.log("Bottom of page");
        }
    };
    

    If you're looking to support older browsers (IE9) use the alias window.pageYOffset which has slightly better support.

提交回复
热议问题