add background music
This commit is contained in:
parent
838fa50add
commit
a501b37e57
@ -16,7 +16,8 @@ You can find all source files in [/nuxt](/nuxt)
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Synthwave design based on https://codepen.io/inegoita/pen/BgdXMw?editors=1000
|
- Synthwave design based on [inegoita Codepen](https://codepen.io/inegoita/pen/BgdXMw?editors=1000)
|
||||||
|
- Background Music by [Three Chain Links - Die Historic](https://soundcloud.com/beardmont)
|
||||||
|
|
||||||
### Build Setup
|
### Build Setup
|
||||||
```bash
|
```bash
|
||||||
|
@ -231,6 +231,34 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ui-control{
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
top: 10px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.ui-control button{
|
||||||
|
border: 3px solid #a684cb;
|
||||||
|
background-color: #b533b3;
|
||||||
|
color: black;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
animation: background-flicker 6s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
.ui-control span{
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.ui-control button{
|
||||||
|
border: 0px solid #fff;
|
||||||
|
background-color: #dd3dda;
|
||||||
|
color: black;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.titleview {
|
.titleview {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
|
BIN
nuxt/assets/sounds/Three Chain Links - Die Historic.mp3
Normal file
BIN
nuxt/assets/sounds/Three Chain Links - Die Historic.mp3
Normal file
Binary file not shown.
@ -209,6 +209,18 @@
|
|||||||
<div class="road-off"></div>
|
<div class="road-off"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="overlay"></div>
|
<div class="overlay"></div>
|
||||||
|
|
||||||
|
<div class="ui-control">
|
||||||
|
<button @click="toggleSound">
|
||||||
|
<span v-if="isSoundEnabled" class="material-icons"> volume_up </span>
|
||||||
|
<span v-else class="material-icons"> volume_off</span>
|
||||||
|
</button>
|
||||||
|
<button @click="playSound">
|
||||||
|
<span v-if="!isSoundPlaying" class="material-icons"> play_arrow</span>
|
||||||
|
<span v-else class="material-icons"> pause </span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Nuxt />
|
<Nuxt />
|
||||||
|
|
||||||
<svg width="0" height="0">
|
<svg width="0" height="0">
|
||||||
@ -270,5 +282,45 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {};
|
import zap from "@/assets/sounds/Three Chain Links - Die Historic.mp3";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
audio: null,
|
||||||
|
isSoundPlaying: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$store.commit("initializeSound");
|
||||||
|
this.audio = new Audio(zap);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggleSound() {
|
||||||
|
this.$store.commit("toggleSound");
|
||||||
|
if(this.isSoundEnabled){
|
||||||
|
this.isSoundPlaying = true;
|
||||||
|
this.audio.play();
|
||||||
|
} else {
|
||||||
|
this.isSoundPlaying = false;
|
||||||
|
this.audio.pause();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
playSound() {
|
||||||
|
if (this.isSoundEnabled && !this.isSoundPlaying) {
|
||||||
|
this.isSoundPlaying = true;
|
||||||
|
this.audio.loop = true;
|
||||||
|
this.audio.play();
|
||||||
|
} else if (this.isSoundEnabled && this.isSoundPlaying) {
|
||||||
|
this.isSoundPlaying = false;
|
||||||
|
this.audio.pause();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isSoundEnabled() {
|
||||||
|
return this.$store.state.isSoundEnabled;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -52,6 +52,16 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Build Configuration: https://go.nuxtjs.dev/config-build
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
build: {},
|
build: {
|
||||||
|
extend(config, ctx) {
|
||||||
|
config.module.rules.push({
|
||||||
|
test: /\.(ogg|mp3|wav|mpe?g)$/i,
|
||||||
|
loader: 'file-loader',
|
||||||
|
options: {
|
||||||
|
name: '[path][name].[ext]'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
23
nuxt/store/index.js
Normal file
23
nuxt/store/index.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
export const state = () => ({
|
||||||
|
isSoundEnabled: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const mutations = {
|
||||||
|
toggleSound(state) {
|
||||||
|
state.isSoundEnabled = !state.isSoundEnabled;
|
||||||
|
localStorage.setItem('isSoundEnabled', state.isSoundEnabled);
|
||||||
|
},
|
||||||
|
initializeSound(state) {
|
||||||
|
const isSoundEnabled = JSON.parse(localStorage.getItem('isSoundEnabled'));
|
||||||
|
if (!isSoundEnabled) {
|
||||||
|
state.isSoundEnabled = false;
|
||||||
|
localStorage.setItem("isSoundEnabled", false);
|
||||||
|
} else if (isSoundEnabled) {
|
||||||
|
state.isSoundEnabled = true;
|
||||||
|
localStorage.setItem("isSoundEnabled", true);
|
||||||
|
} else {
|
||||||
|
state.isSoundEnabled = true;
|
||||||
|
localStorage.setItem("isSoundEnabled", true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user