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

后端 未结 19 1007
你的背包
你的背包 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:41

    Two solutions I found that worked for me:

      window.addEventListener('scroll', function(e) {
        if (
          window.innerHeight + document.documentElement.scrollTop ===
          document.documentElement.offsetHeight
        ) {
          console.log('You are at the bottom')
        }
      })
    

    And the other:

      window.addEventListener('scroll', function(e) {
        if (
          window.innerHeight + window.pageYOffset ===
          document.documentElement.offsetHeight
        ) {
          console.log('You are at the bottom')
        }
      })
    

提交回复
热议问题