js 判断滚动条是否滑动到了底部

const scrollToTheEndFn = () => {
let scrollTopFn = 0; // 滚动条的高度
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}

let clientHeightFn = 0;
if (document.body.clientHeight && document.documentElement.clientHeight) {
  clientHeight = Math.min(
    document.body.clientHeight,
    document.documentElement.clientHeight,
  );
} else {
  clientHeight = Math.max(
    document.body.clientHeight,
    document.documentElement.clientHeight,
  );
}

const getScrollHeightFn = Math.max(
  document.body.scrollHeight,
  document.documentElement.scrollHeight,
);

if (scrollTop + clientHeight >= getScrollHeight ) {
 //说明是到了底部了
}

};

你可能感兴趣的:(javascript,前端,开发语言)