张延森 vor 3 Jahren
Ursprung
Commit
22e47083a8

BIN
src/assets/indexImg/loading.png Datei anzeigen


BIN
src/assets/indexImg/loadingBgc.jpg Datei anzeigen


BIN
src/assets/indexImg/loading_bar.png Datei anzeigen


public/images/paused.png → src/assets/indexImg/paused.png Datei anzeigen


public/images/play.png → src/assets/indexImg/play.png Datei anzeigen


+ 50
- 4
src/components/BgMusic.vue Datei anzeigen

@@ -1,6 +1,6 @@
1 1
 <template>
2
-  <div class="bg-music">
3
-
2
+  <div class="bg-music" :class="{ ['icon-playing']: playing }" @click="handleClick" v-show="show">
3
+    <audio :src="url" ref="audioRef" loop @canplay="show = true" @play="handlePlay"></audio>
4 4
   </div>
5 5
 </template>
6 6
 
@@ -11,15 +11,61 @@ export default {
11 11
     const { origin, pathname } = window.location
12 12
 
13 13
     return {
14
+      show: false,
15
+      playing: false,
14 16
       url: `${origin}${pathname}/bg.mp3`
15 17
     }
18
+  },
19
+  mounted() {
20
+    document.body.addEventListener("click", this.handleClick);
21
+  },
22
+  methods: {
23
+    handleClick() {
24
+      if (!this.show || !this.$refs.audioRef) return;
25
+
26
+      if (this.playing) {
27
+        this.$refs.audioRef.pause();
28
+      } else {
29
+        this.$refs.audioRef.play();
30
+      }
31
+
32
+      this.playing = !this.playing
33
+    },
34
+
35
+    handlePlay() {
36
+      document.body.removeEventListener("click", this.handleClick);
37
+    }
16 38
   }
17 39
 }
18 40
 </script>
19 41
 
20 42
 <style lang="less" scoped>
21 43
 .bg-music {
22
-  width: 64px;
23
-  height: 64px;
44
+  position: fixed;
45
+  top: 1em;
46
+  right: 1em;
47
+  z-index: 10;
48
+
49
+  width: 2em;
50
+  height: 2em;
51
+  background-image: url('~@/assets/indexImg/play.png');
52
+  background-repeat: no-repeat;
53
+  background-size: 100% 100%;
54
+
55
+  &.icon-playing {
56
+    background-image: url('~@/assets/indexImg/paused.png');
57
+    animation: musicrotate 3s linear infinite;
58
+  }
59
+
60
+  & > audio {
61
+    max-width: 1px;
62
+    max-height: 1px;
63
+  }
64
+}
65
+
66
+@keyframes musicrotate {
67
+  100% {
68
+    transform: rotate(360deg);
69
+  }
24 70
 }
25 71
 </style>

+ 3
- 1
src/pages/Honghe.vue Datei anzeigen

@@ -1,5 +1,6 @@
1 1
 <template>
2 2
   <div class="index-box">
3
+    <bg-music />
3 4
     <popup :show="showPopup" @cancel="cancelFrom" :current-month="currentMonth" />
4 5
     <MyWinning :show="showMyWinning" :current-month="currentMonth" />
5 6
     <img class="topImage" src="../assets/indexImg/indexBgctop.jpg" alt />
@@ -143,7 +144,8 @@ export default {
143 144
   components: {
144 145
     Popup: () => import('@/components/Popup.vue'),
145 146
     WinningPopup: () => import('@/components/WinningPopup.vue'),
146
-    ImgBox: () => import('@/components/imgbox.vue')
147
+    ImgBox: () => import('@/components/imgbox.vue'),
148
+    BgMusic: () => import('@/components/BgMusic.vue'),
147 149
   },
148 150
   data() {
149 151
     return {