首页 > 其他 > 详细

页面添加h5背景音乐

时间:2017-09-12 10:35:18      阅读:314      评论:0      收藏:0      [点我收藏+]
<div id="audio_btn" class="rotate">
    <audio loop src="bg_audio.mp3" id="media" autoplay="" preload=""></audio>
</div>

#audio_btn {
     width: 30px;
     height: 30px;
     background-image: url(normalmusic.svg);
     background-size: contain;
 }
 
 .rotate {
    -webkit-animation: rotating 1.2s linear infinite;
     -moz-animation: rotating 1.2s linear infinite;
     -o-animation: rotating 1.2s linear infinite;
     animation: rotating 1.2s linear infinite
 }
 
 @-webkit-keyframes rotating {
     from { -webkit-transform: rotate(0) }
     to { -webkit-transform: rotate(360deg) }
 }
 
 @keyframes rotating {
     from { transform: rotate(0) }
     to { transform: rotate(360deg) }
 }
 @-moz-keyframes rotating {
     from { -moz-transform: rotate(0) }
     to { -moz-transform: rotate(360deg) }
 }



$("#audio_btn").click(function(){
     $(this).toggleClass("rotate"); //控制音乐图标 自转或暂停
 })
var x = document.getElementById("media"); 
 $(function(){
     $("#audio_btn").click(function(){
         $(this).toggleClass("rotate"); //控制音乐图标 自转或暂停
         
         //控制背景音乐 播放或暂停            
         if($(this).hasClass("rotate")){
             x.play();
         }else{
             x.pause();
         }
     })
 });

  

页面添加h5背景音乐

原文:http://www.cnblogs.com/zhangrenjie/p/7508770.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!