设为首页收藏本站

IITT网络服务中心

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2992|回复: 0
打印 上一主题 下一主题

网页插入背景音乐

[复制链接]

453

主题

399

帖子

1764

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1764
跳转到指定楼层
楼主
发表于 2016-4-23 18:32:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. <style type="text/css">
  2. .btnAudio{ width:36px; height:36px; position:absolute; right:30px; top:18px; overflow:hidden; background:url("http://open.storage.ailxcloud.com/o_1a8ql8dr2sjc1fap6161u3bj8ba.png") left top no-repeat; z-index:100;}
  3. .rotate1circle{-webkit-animation:rotate1circle 1s linear infinite;}
  4. @-webkit-keyframes rotate1circle {
  5.         0% {
  6.                 -webkit-transform-origin:center center;
  7.                 -webkit-transform:rotate(0deg);
  8.         }
  9.         100% {
  10.                 -webkit-transform-origin:center center;
  11.                 -webkit-transform:rotate(360deg);
  12.         }
  13. }
  14. </style>

  15. <section class="u-audio hidden" data-src="http://网址.mp3"></section>
  16. <div class="btnAudio" id="btnAudio"></div>

  17. <script>
  18. var bg_audio_val = true;
  19. var bg_audio = new Audio();
  20. function audio_init(){
  21.         var options_audio = {
  22.                 loop: true,
  23.                 preload: "auto",
  24.                 src: $('.u-audio').attr('data-src')
  25.         }
  26.         for (var key in options_audio) {
  27.                 bg_audio[key] = options_audio[key];
  28.         }
  29.         bg_audio.load();
  30.         audio_addEvent();
  31.         bg_audio.play();
  32. }
  33. function audio_addEvent(){
  34.         $("#btnAudio").on('click', audio_control);
  35.         $(bg_audio).on('play',function(){
  36.                 bg_audio_val = false;
  37.                 $('#btnAudio').addClass('rotate1circle');
  38.         })
  39.         $(bg_audio).on('pause',function(){
  40.                 $('#btnAudio').removeClass('rotate1circle');
  41.         })
  42. }
  43. function audio_control(){
  44.         if(!bg_audio_val){
  45.                 bg_audio.pause();
  46.                 bg_audio_val = true;
  47.         }else{
  48.                 bg_audio.play();
  49.         }
  50. }
  51. audio_init();
  52. </script>
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|IITT网络服务中心    

GMT+8, 2024-4-26 03:47 , Processed in 0.065293 second(s), 24 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表