简体   繁体   English

如何知道元素何时滚动到底部

[英]How to know when element has been scrolled to the bottom

According to the first answer to the question at Stackoverflow , it can be known when element.innerHeight + element.scrollTop is greater than or equal to element.offsetHeight . 根据Stackoverflow上对该问题的第一个答案,可以知道element.innerHeight + element.scrollTop大于或等于element.offsetHeight Shouldn't it be element.innerHeight + element.scrollTop is greater than or equal to element.scrollHeight ? 它不应该是element.innerHeight + element.scrollTop大于或等于element.scrollHeight吗? offsetHeight just includes the padding while calculating the visible height, what we want here is to find whether the scrolled height plus the visible height equals the total height, isn't the total height given by scrollHeight ? offsetHeight在计算可见高度时仅包括填充,我们在这里想要查找滚动高度加上可见高度是否等于总高度,不是scrollHeight给定的总高度吗?

In general, yes. 一般来说,是的。 However, that question is about the page specifically, and the <body> element doesn't actually scroll; 但是,这个问题是专门针对页面的,而<body>元素实际上并没有滚动。 the viewport does. 视口会。

Try it out: make sure this page scrolls, then open a console: 尝试一下:确保该页面滚动,然后打开一个控制台:

> document.body.offsetHeight === document.body.scrollHeight
true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM