页面添加h5背景音乐

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<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();
         }
     })
 });

  

posted @   异地大光码  阅读(3579)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示