张延森 2 years ago
parent
commit
f38f219cc8
4 changed files with 32 additions and 5 deletions
  1. BIN
      public/audios/entrance.mp3
  2. 5
    0
      src/App.vue
  3. 26
    4
      src/components/Loader.vue
  4. 1
    1
      src/components/Mask.vue

BIN
public/audios/entrance.mp3 View File


+ 5
- 0
src/App.vue View File

27
   const { onStart, onEnd } = scroll(window.document);
27
   const { onStart, onEnd } = scroll(window.document);
28
 
28
 
29
   onStart(() => {
29
   onStart(() => {
30
+    if (!entranceAudioPlayed.value) {
31
+      entranceAudioRef.value.play()
32
+      entranceAudioPlayed.value = true
33
+    }
34
+
30
     fixedLogoHidden.value = true;
35
     fixedLogoHidden.value = true;
31
   })
36
   })
32
 
37
 

+ 26
- 4
src/components/Loader.vue View File

1
 <template>
1
 <template>
2
   <div 
2
   <div 
3
     class="loader-wrapper"
3
     class="loader-wrapper"
4
-    :class="{ loaded: !loading }"
4
+    :class="{ loaded: !loading, mask: maskReadyRef }"
5
     :style="visibleStyle"
5
     :style="visibleStyle"
6
     @touchmove.prevent
6
     @touchmove.prevent
7
     @mousewheel.prevent
7
     @mousewheel.prevent
16
     <!-- <div class="loader-section section-top"></div>
16
     <!-- <div class="loader-section section-top"></div>
17
     <div class="loader-section section-bottom"></div>     -->
17
     <div class="loader-section section-bottom"></div>     -->
18
     <MaskVue ref="maskRef" @end="onEnd"/>
18
     <MaskVue ref="maskRef" @end="onEnd"/>
19
+    <audio :src="entranceAudio" style="max-width: 1px;max-height: 1px;" ref="entranceAudioRef" ></audio>
19
   </div>
20
   </div>
20
 </template>
21
 </template>
21
 
22
 
23
 import { computed, onMounted, ref, watch } from "vue"
24
 import { computed, onMounted, ref, watch } from "vue"
24
 import MaskVue from "./Mask.vue";
25
 import MaskVue from "./Mask.vue";
25
 
26
 
27
+const entranceAudio = './audios/entrance.mp3';  
28
+
26
 const props = defineProps({
29
 const props = defineProps({
27
   tip: {
30
   tip: {
28
     type: String,
31
     type: String,
37
 
40
 
38
 const elRef = ref();
41
 const elRef = ref();
39
 const maskRef = ref();
42
 const maskRef = ref();
43
+const maskReadyRef = ref(false);
40
 const progressStyle = computed(() => ({ width: `${props.percent}%` }));
44
 const progressStyle = computed(() => ({ width: `${props.percent}%` }));
41
-const visibleStyle = ref({  })
45
+const visibleStyle = ref({})
46
+const entranceAudioRef = ref()
47
+const entranceAudioReady = ref(false)
48
+
42
 const onEnd = () => {
49
 const onEnd = () => {
43
   visibleStyle.value = { display: 'none' }
50
   visibleStyle.value = { display: 'none' }
44
 }
51
 }
48
   e.preventDefault();
55
   e.preventDefault();
49
 }
56
 }
50
 
57
 
58
+const playMask = () => {
59
+  if (maskReadyRef.value && entranceAudioReady.value) {
60
+    entranceAudioRef.value.play();
61
+    maskRef.value.start();
62
+  }
63
+}
64
+
51
 watch(() => props.loading, (newVal, oldVal) => {
65
 watch(() => props.loading, (newVal, oldVal) => {
52
   if (oldVal && !newVal) {
66
   if (oldVal && !newVal) {
53
-    maskRef.value.start();
67
+    maskReadyRef.value = true;
68
+    playMask();
54
   }
69
   }
55
 })
70
 })
56
 
71
 
72
+onMounted(() => {
73
+  document.addEventListener("WeixinJSBridgeReady", function () {
74
+    entranceAudioReady.value = true;
75
+    playMask();
76
+  }, false);
77
+})
78
+
57
 </script>
79
 </script>
58
 
80
 
59
 
81
 
115
     bottom: 0;
137
     bottom: 0;
116
   }
138
   }
117
 
139
 
118
-  &.loaded {
140
+  &.loaded.mask {
119
     // visibility: hidden;
141
     // visibility: hidden;
120
     // transform: translateX(-100%);
142
     // transform: translateX(-100%);
121
     // transition: all 0.3s 1s ease-out;
143
     // transition: all 0.3s 1s ease-out;

+ 1
- 1
src/components/Mask.vue View File

37
 
37
 
38
   const xStart = 60;
38
   const xStart = 60;
39
   const yStart = 90;
39
   const yStart = 90;
40
-  const speed = 20;
40
+  const speed = 10;
41
   const draw = () => {
41
   const draw = () => {
42
     i += speed;
42
     i += speed;
43
     const canv = cvsRef.value;
43
     const canv = cvsRef.value;