当前位置: 首页 > 源码分享 > 正文

本博客首页背景音乐HTML代码

消失的彩虹海 发表于2015年11月28日 21:57
看到很多人想要,所以就分享出来了,以下就是本博客首页那个旋转音乐图标的代码。其中的 http://wap.gx.10086.cn/xhtml/images/healthassist/bgmusic.mp3 是背景音乐的链接,大家可以自由替换。
<style type="text/css">
.btnAudio{ width:36px; height:36px; position:absolute; right:30px; top:18px; overflow:hidden; background:url("http://pan.cccyun.cc/view.php/7a1a6d1c1426c7ce866712f1c058b69d.png") left top no-repeat; z-index:100;}
.rotate1circle{-webkit-animation:rotate1circle 1s linear infinite;}
@-webkit-keyframes rotate1circle {
        0% {
                -webkit-transform-origin:center center;
                -webkit-transform:rotate(0deg);
        }
        100% {
                -webkit-transform-origin:center center;
                -webkit-transform:rotate(360deg);
        }
}
</style>
 
<section class="u-audio hidden" data-src="http://wap.gx.10086.cn/xhtml/images/healthassist/bgmusic.mp3"></section>
<div class="btnAudio" id="btnAudio"></div>
 
<script>
var bg_audio_val = true;
var bg_audio = new Audio();
function audio_init(){
        var options_audio = {
                loop: true,
                preload: "auto",
                src: $('.u-audio').attr('data-src')
        }
        for (var key in options_audio) {
                bg_audio[key] = options_audio[key];
        }
        bg_audio.load();
        audio_addEvent();
        bg_audio.play();
}
function audio_addEvent(){
        $("#btnAudio").on('click', audio_control);
        $(bg_audio).on('play',function(){
                bg_audio_val = false;
                $('#btnAudio').addClass('rotate1circle');
        })
        $(bg_audio).on('pause',function(){
                $('#btnAudio').removeClass('rotate1circle');
        })
}
function audio_control(){
        if(!bg_audio_val){
                bg_audio.pause();
                bg_audio_val = true;
        }else{
                bg_audio.play();
        }
}
audio_init();
</script>
全文完
本文标签:
本文标题: 本博客首页背景音乐HTML代码
本文链接: http://blog.cccyun.cn/m/?post=209

〓 随机文章推荐

共有17755阅 / 13我要评论
  1. 良辰13楼
    彩虹大佬,我的网页加了这个音乐代码。在浏览器可以正常播放,但是在QQ中打开网页,音乐图标在转但是不播放音乐怎么解决呢?
  2. 放在什么位置呢?
  3. 凌鑫11楼
    不错噢
  4. 流星10楼
    不知道怎么弄不显示
  5. 旋律很好听
  6. 8楼
    @admin:代码放那
  7. 滴途7楼
    求JS代码
  8. Secret6楼
    少了一段JS。
  9. 拿走了
  10. admin4楼
    背景音乐代码不错   直接放在body里面的吗
1 2

发表你的评论吧返回顶部

!评论内容需包含中文

请勾选本项再提交评论