Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 1.08 KB

bottom-visible.md

File metadata and controls

37 lines (24 loc) · 1.08 KB
标题 标签
bottomVisible(判断是否滚动到底部) browser,beginner(浏览器,初学者)

检查页面底部是否可见。

  • 使用 scrollYscrollHeightclientHeight 确定页面底部是否可见。

代码如下:

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>