vue 页面 添加背景音乐


 

背景音乐

添加背景音乐 并有单击事件   循环播放

 

<template>
    <div id="page">
        <div style="width: 100%" class="flex-container column">
            <video id="video" src="../static/audios/bgm3.mp3" controls="controls" hidden="hidden" autoplay="autoplay"  loop="loop"> </video>

            <img  id="img" class="play" style="transform: translate(-1584.4%, 121.5%) scale(1)" :src="sound" @click="play()">

        </div>
    </div>
</template>


<script>
 export default {
        data() {
            return {
                sound: require('../static/img/33.png'),
        },
         methods: {
            play(){
                let vo = document.getElementById("video")
                if(this.sound == require('../static/img/33.png')){
                    this.sound = require('../static/img/22.png')
                    vo.autoplay = true
                    vo.play()
                }
                else{
                    this.sound = require('../static/img/33.png')
                    vo.pause()
                }

            }
}
</script>

 

目录结构

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM