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

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

    Surprisingly none of the solutions worked for me. I think it's because my css was messed up, and body didn't wrap around all of the content when using height: 100% (don't know why yet). However while looking for a solution I've came up with something well... basically the same, but maybe it's worth to look at - I'm new into programming so sorry if it's doing the same slower, is less supported or something like that...

    window.onscroll = function(evt) {
      var check = (Element.getBoundingClientRect().bottom - window.innerHeight <= 0) ? true : false;
      if (check) { console.log("You're at the bottom!"); }
    };
    

提交回复
热议问题