H5音樂自動播放ios//禁止安卓手機圖片點擊

來源:互聯網
上載者:User

標籤:設定   jsb   ack   ges   style   load   ext   auto   color   

定義音樂按鈕

<div id="music-btn" class="o-play" style="width: 24px; height: 24px; display: block; position: absolute; top: 12px; right: 12px; z-index: 9999; background: url(images/musicbtn.png) no-repeat center/cover;"></div>

音樂 
<audio id="o-music" src="img/bg.mp3" class="muisc" preload="preload" autoplay="autoplay" loop="loop"></audio>

src 屬性規定要播放的視頻的 URL

preload 屬性規定是否在頁面載入後載入視頻。如果設定了 autoplay 屬性,則忽略該屬性。loop 屬性規定當視頻結束後將重新開始播放。設定該屬性,則視頻將迴圈播放。 autoplay 屬性設定為自動播放的 video 元素:  autoplay 屬性規定一旦視頻就緒馬上開始播放。

js檔案

<script type="text/javascript">

  ios自動播放
  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(‘o-music‘);
  音樂按鈕
  $(‘#music-btn‘).on(‘click‘, function(){
    if(!document.querySelector(‘#o-music‘).paused){
      document.querySelector(‘#o-music‘).pause();
      $(this).removeClass(‘o-play‘);
    }else{
      document.querySelector(‘#o-music‘).play();
      $(this).addClass(‘o-play‘);
    }
  });
//禁止安卓手機圖片點擊
  for(var i=0; i<document.querySelectorAll(‘img‘).length; i++){
    document.querySelectorAll(‘img‘)[i].addEventListener(‘click‘, function(e){
    e.preventDefault();
  })
}
</script>

H5音樂自動播放ios//禁止安卓手機圖片點擊

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.