李志伟 3 年之前
父節點
當前提交
503a8143d9
共有 2 個檔案被更改,包括 21 行新增6 行删除
  1. 16
    5
      src/components/BgMusic.vue
  2. 5
    1
      src/components/MusicOnce.vue

+ 16
- 5
src/components/BgMusic.vue 查看文件

1
 <template>
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
   </div>
15
   </div>
5
 </template>
16
 </template>
6
 
17
 
18
   },
29
   },
19
   mounted() {
30
   mounted() {
20
     document.body.addEventListener('click', this.handleClick)
31
     document.body.addEventListener('click', this.handleClick)
21
-
32
+    this.$refs.audioRef.volume = 0.3
22
     this.$nextTick(() => {
33
     this.$nextTick(() => {
23
       this.handleIOSAudio()
34
       this.handleIOSAudio()
24
     })
35
     })
64
 
75
 
65
   width: 2em;
76
   width: 2em;
66
   height: 2em;
77
   height: 2em;
67
-  background-image: url('~@/assets/ButtonImage/play.png');
78
+  background-image: url("~@/assets/ButtonImage/play.png");
68
   background-repeat: no-repeat;
79
   background-repeat: no-repeat;
69
   background-size: 100% 100%;
80
   background-size: 100% 100%;
70
 
81
 
71
   &.icon-playing {
82
   &.icon-playing {
72
-    background-image: url('~@/assets/ButtonImage/paused.png');
83
+    background-image: url("~@/assets/ButtonImage/paused.png");
73
     animation: musicrotate 3s linear infinite;
84
     animation: musicrotate 3s linear infinite;
74
   }
85
   }
75
 
86
 

+ 5
- 1
src/components/MusicOnce.vue 查看文件

1
 <template>
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
 </template>
7
 </template>
4
 
8
 
5
 <script setup>
9
 <script setup>