李志伟 3 years ago
parent
commit
503a8143d9
2 changed files with 21 additions and 6 deletions
  1. 16
    5
      src/components/BgMusic.vue
  2. 5
    1
      src/components/MusicOnce.vue

+ 16
- 5
src/components/BgMusic.vue View File

@@ -1,6 +1,17 @@
1 1
 <template>
2
-  <div class="bg-music" :class="{ ['icon-playing']: playing }" @click="handleClick" v-show="show">
3
-    <audio :src="url" ref="audioRef" loop @loadedmetadata="show = true" @play="handlePlay"></audio>
2
+  <div
3
+    v-show="show"
4
+    class="bg-music"
5
+    :class="{ ['icon-playing']: playing }"
6
+    @click="handleClick"
7
+  >
8
+    <audio
9
+      ref="audioRef"
10
+      :src="url"
11
+      loop
12
+      @loadedmetadata="show = true"
13
+      @play="handlePlay"
14
+    />
4 15
   </div>
5 16
 </template>
6 17
 
@@ -18,7 +29,7 @@ export default {
18 29
   },
19 30
   mounted() {
20 31
     document.body.addEventListener('click', this.handleClick)
21
-
32
+    this.$refs.audioRef.volume = 0.3
22 33
     this.$nextTick(() => {
23 34
       this.handleIOSAudio()
24 35
     })
@@ -64,12 +75,12 @@ export default {
64 75
 
65 76
   width: 2em;
66 77
   height: 2em;
67
-  background-image: url('~@/assets/ButtonImage/play.png');
78
+  background-image: url("~@/assets/ButtonImage/play.png");
68 79
   background-repeat: no-repeat;
69 80
   background-size: 100% 100%;
70 81
 
71 82
   &.icon-playing {
72
-    background-image: url('~@/assets/ButtonImage/paused.png');
83
+    background-image: url("~@/assets/ButtonImage/paused.png");
73 84
     animation: musicrotate 3s linear infinite;
74 85
   }
75 86
 

+ 5
- 1
src/components/MusicOnce.vue View File

@@ -1,5 +1,9 @@
1 1
 <template>
2
-  <audio class="mp3-once" :src="src" ref="audioRef"></audio>
2
+  <audio
3
+    ref="audioRef"
4
+    class="mp3-once"
5
+    :src="src"
6
+  />
3 7
 </template>
4 8
 
5 9
 <script setup>