音频播放:
两种方式:1.利用audio,2,利用SoundJS
场景:点击页面的按钮,控制音频播放与暂停
1.利用audio
html:
<a class="btn-music antime" href="javascript:;" title="音乐"></a>
<audio id="music" loop="loop" src="//game.gtimg.cn/images/lol/m/act/a20181028back/RISE.mp3" preload></audio>
js:
//音乐播放
var music = document.getElementById('music');
document.addEventListener("WeixinJSBridgeReady", function () {//微信内初始化
music.play();
});
$(window).ready(function(){//其他平台的初始化
music.play();
});
//关闭音乐
var musicState = true;
$('.btn-music').click(function(){
if(musicState){
$('.btn-music').addClass('suspend');
$('.btn-music').removeClass('antime');
music.pause();
musicState = false;
}
else{
$('.btn-music').rem