首页 技术 正文
技术 2022年11月8日
0 收藏 328 点赞 1,598 浏览 2358 个字

html:

<script src="js/jquery-2.1.3.min.js"></script>
<div id="soundIconPlay" onclick="soundIconOff()" class="soundIcon soundIconPlay"></div>
<div id="soundIconOff" onclick="soundIconPlay()" class="soundIcon soundIconOff hide"></div>
<div class="audio" style="width:0; height:0px; overflow:hidden; text-indent:-999px;">
<audio id="bgmusic" loop="loop" autoplay="autoplay" src="data:images/bgmusic.mp3" controls=true></audio>
</div>
//关键: 先写页面再引js,否则会报Cannot read property 'pause/play' of null
<script type="text/javascript">
function init() {
var myAudio = document.getElementById("bgmusic");
myAudio.addEventListener('ended', loopAudio, false);
}
function loopAudio() {
var myAudio = document.getElementById("bgmusic");
myAudio.play();
}
//加载页面播放背景音乐(ios无法实现,只能模拟触屏实现自动播放)
function audioAutoPlay(id){
var audio = document.getElementById('bgmusic'),
play = function(){
audio.play();
document.removeEventListener("touchstart",play, false);
};
audio.play();
document.addEventListener("WeixinJSBridgeReady", function () {
play();
}, false);
document.addEventListener('YixinJSBridgeReady', function() {
play();
}, false);
document.addEventListener("touchstart",play, false);
}
audioAutoPlay('mybgaudio');
</script>
<script type="text/javascript">
var oAudioOFF = "1";
var oAudio = document.getElementById('bgmusic');
function soundIconPlay(){
    oAudioOFF = "1";
    oAudio.play();
    $('#soundIconPlay').show();
    $('#soundIconOff').hide();
};
function soundIconOff(){
    oAudioOFF = "0";
    oAudio.pause();
    $('#soundIconPlay').hide();
    $('#soundIconOff').show();
};
</script>

css:

.soundIcon{
position:absolute;
top:.1rem;
right:.1rem;
z-index:1;
}
.soundIconPlay{
width:.4rem;
height:.4rem;
background:url('../images/musicOn.png') no-repeat;
background-size:100%;
animation:bgRotate 1.2s infinite linear;
-o-animation:bgRotate 1.2s infinite linear;
-moz-animation:bgRotate 1.2s infinite linear;
-webkit-animation:bgRotate 1.2s infinite linear
}
.soundIconOff{
width:.4rem;
height:.4rem;
background:url('../images/musicOff.png') no-repeat;
background-size:100%;
animation:initial;
-o-animation:initial;
-moz-animation:initial;
-webkit-animation:initial
}
@keyframes bgRotate{
from{transform:rotate(0deg)}
to{transform:rotate(360deg)}
}
@-webkit-keyframes bgRotate{
from{-webkit-transform:rotate(0deg)}
to{-webkit-transform:rotate(360deg)}
}
@-moz-keyframes bgRotate{
from{-moz-transform:rotate(0deg)}
to{-moz-transform:rotate(360deg)}
}
@-o-keyframes bgRotate{
from{-o-transform:rotate(0deg)}
to{-o-transform:rotate(360deg)}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898