标题 | 标签 |
---|---|
bottomVisible(判断是否滚动到底部) | browser,beginner(浏览器,初学者) |
检查页面底部是否可见。
- 使用
scrollY
、scrollHeight
和clientHeight
确定页面底部是否可见。
代码如下:
const bottomVisible = () => {
const { clientHeight, scrollHeight } = document.documentElement;
const { scrollY } = window;
return clientHeight + scrollY >= (scrollHeight || clientHeight);
};
ts 代码如下:
调用方式:
bottomVisible(); // true or false
应用场景
以下是一个实战示例:
结果如下:
<iframe src="codes/javascript/html/bottom-visible.html"></iframe>