zoukankan      html  css  js  c++  java
  • js-html音乐播放

    <img src="images/music.png" id="music" class="rotate">
    <audio src="images/music.mp3?v=982" autoplay="autoplay" loop id="muc"></audio>

    css

    /*音乐*/#music {

        position: fixed;
        top: 3%;
        right: 16px;
        z-index: 9999999;
      }
    .rotate {
       animation: circle 2s linear infinite;
      }
    @keyframes circle{

    100% {
         transform: rotate(360deg);
      }
    }

    js

    var mus = document.getElementById("music");
    var audio = document.getElementById("muc");
    mus.onclick = function() {
                 if(audio.paused) {
                              audio.play();
                              mus.classList.add("rotate");
                 } else {
                             audio.pause();
                             mus.classList.remove("rotate");
                  }
    }

    function audioAutoPlay(id) {
        var audio = document.getElementById(id),
        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('music');

    针对IOS以上代码不支持打开页面自动播放

    搬运工: http://www.mamicode.com/info-detail-1505268.html

    2018-5-12日周六加班!!!!因为项目下午要上线,需要兼容ios音乐自动播放,且已经解决问题,在此做一个笔记也可以帮助看到这篇笔记的盆友

    1.首先是要链接js:

    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

    2.页面添加:

    document.addEventListener("WeixinJSBridgeReady", function () {
         WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
                  document.getElementById('allMusic1').play();
          });
    }, false);

     ok以上就是我项目中兼容ios时写的代码

  • 相关阅读:
    TortoiseGit日常使用指南
    Ajax在MVC中的应用
    STL源码学习内存管理
    功能最强大的.Net代码生成器——EasyCode
    TortoiseGit使用入门
    负载均衡时数据包流程详解
    C++异步编程 for VS2011
    (译)一个通用快速的反射方法调用
    移位运算
    使用Autofac在ASP.NET Web API上实现依赖注入
  • 原文地址:https://www.cnblogs.com/liuqingxia/p/7772701.html
Copyright © 2011-2022 走看看