张延森 2 yıl önce
ebeveyn
işleme
5f89b887d8
3 değiştirilmiş dosya ile 57 ekleme ve 7 silme
  1. 7
    4
      src/App.vue
  2. 1
    3
      src/components/Image.vue
  3. 49
    0
      src/utils/scroll.js

+ 7
- 4
src/App.vue Dosyayı Görüntüle

@@ -4,6 +4,7 @@ import Loader from '@/components/Loader.vue';
4 4
 import ScrollDown from '@/components/ScrollDown.vue';
5 5
 import Image from '@/components/Image.vue';
6 6
 import { preload } from '@/utils/preload';
7
+import scroll from '@/utils/scroll'
7 8
 
8 9
 const fixedLogo = './fixed-logo.png';
9 10
 
@@ -11,6 +12,7 @@ const loading = ref(true);
11 12
 const percent = ref(0);
12 13
 const resources = ref([]);
13 14
 const fixedLogoHidden = ref(false);
15
+const unScroll = ref()
14 16
 
15 17
 const updateCallback = (num) => {
16 18
   percent.value = Math.round(num * 100);
@@ -22,13 +24,14 @@ const onClick = () => {
22 24
 }
23 25
 
24 26
 onMounted(() => {
25
-  window.document.body.addEventListener('touchmove', () => {
27
+  const { onStart, onEnd } = scroll(window.document);
28
+
29
+  onStart(() => {
26 30
     fixedLogoHidden.value = true;
27 31
   })
28
-  window.document.body.addEventListener('touchend', () => {
29
-    setTimeout(() => {
32
+
33
+  onEnd(() => {
30 34
       fixedLogoHidden.value = false;
31
-    }, 600);
32 35
   })
33 36
 
34 37
   preload(updateCallback).then((res) => {

+ 1
- 3
src/components/Image.vue Dosyayı Görüntüle

@@ -1,6 +1,5 @@
1 1
 <template>
2 2
   <div class="img-wrapper">
3
-    <Fog v-if="showFog" />
4 3
     <img :src="resource.img.src" @load="onLoad" alt="">
5 4
     <div v-if="resource.playBtn" class="paybtn" :style="btnStyle" @click="onPlayBtn">
6 5
       <AudioPlayingVue :style="iconStyle" />
@@ -12,7 +11,6 @@
12 11
 <script setup>
13 12
 import { computed, ref, watch } from 'vue';
14 13
 import { useModel } from '@zjxpcyc/vue-tiny-store';
15
-import Fog from './Fog.vue';
16 14
 import AudioPlayingVue from './AudioPlaying.vue';
17 15
 
18 16
 const [current, updateCurrent] = useModel('audio');
@@ -81,7 +79,7 @@ const onLoad = (e) => {
81 79
 
82 80
 <style lang="less" scoped>
83 81
 .img-wrapper {
84
-  margin-top: -0.1px; // 解决 iphone13 白边问题
82
+  margin-top: -0.5px; // 解决 iphone13 白边问题
85 83
   position: relative;
86 84
 
87 85
   .paybtn {

+ 49
- 0
src/utils/scroll.js Dosyayı Görüntüle

@@ -0,0 +1,49 @@
1
+
2
+export default function scroll(dom) {
3
+  let scrolling = false;
4
+  let t1 = undefined;
5
+  const timeDiff = 500;
6
+
7
+  const scrollStart = { value: undefined };
8
+  const scrollEnd = { value: undefined };
9
+  
10
+  const onScroll = (e) => {
11
+    console.log('scrolling', scrolling, e);
12
+
13
+    if (!scrolling) {
14
+      if (typeof scrollStart.value === 'function') {
15
+        scrollStart.value(e);
16
+      }
17
+    }
18
+
19
+    scrolling = true;
20
+
21
+    if (t1) {
22
+      // 如果存在计时器 t1, 说明在滚动
23
+      // 立即销毁 t1
24
+      clearTimeout(t1);
25
+      t1 = undefined;
26
+    }
27
+
28
+    // t1 主要的作用是触发 stop 事件
29
+    t1 = setTimeout(() => {
30
+      // 如果 t1 被触发, 没有被销毁 说明没有在滚动
31
+      clearTimeout(t1);
32
+      t1 = undefined;
33
+      scrolling = false;
34
+
35
+      if (typeof scrollEnd.value === 'function') {
36
+        scrollEnd.value(e);
37
+      }
38
+    }, timeDiff);
39
+  }
40
+
41
+  console.log('scroll', dom);
42
+  dom.addEventListener('scroll', onScroll);
43
+
44
+  return {
45
+    onStart: cb => scrollStart.value = cb,
46
+    onEnd: cb => scrollEnd.value = cb,
47
+    destroy: () => dom.removeEventListener('scroll', onScroll)
48
+  }
49
+}