Your Name 2 年前
父节点
当前提交
cca57c2c76
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8
    4
      src/components/ScrollDown.vue

+ 8
- 4
src/components/ScrollDown.vue 查看文件

@@ -10,10 +10,14 @@ import { onBeforeUnmount, onMounted, ref } from "vue"
10 10
 const style = ref({ opacity: 1 })
11 11
 
12 12
 const onScroll = (e) => {
13
-  const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
14
-  const offsetHeight = document.documentElement.offsetHeight || document.body.offsetHeight;
15
-  const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
16
-	if (offsetHeight + scrollTop >= scrollHeight) {
13
+  // const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
14
+  // const offsetHeight = document.documentElement.offsetHeight || document.body.offsetHeight;
15
+  // const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
16
+  // const isBottom = offsetHeight + scrollTop >= scrollHeight;
17
+
18
+  const isBottom = (window.innerHeight + window.scrollY) >= (document.body.scrollHeight - 100);
19
+
20
+	if (isBottom) {
17 21
 		style.value = { opacity: 0 }
18 22
     console.log('已到底部');
19 23
 	} else {