H5 Music Auto Play ios//no Android phone pictures click

Source: Internet
Author: User

Define music Buttons

<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>

Music
<audio id= "O-music" src= "Img/bg.mp3" class= "Muisc" preload= "preload" autoplay= "AutoPlay" loop= "loop" ></ Audio>

SRC attribute specifies the URL of the video to play

The Preload property specifies whether to load the video after the page is loaded. If the AutoPlay property is set, the property is ignored. The Loop property specifies that playback starts again when the video ends. Set this property, the video will loop back. the AutoPlay property is set to the video element that is automatically played: The AutoPlay property specifies that the video is ready to play as soon as it is prepared.

JS file

<script type= "Text/javascript" >

   iOS auto Play
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 Button
$ (' #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 ');
}
});
//Disable Android phone picture click
for (var i=0; I<document.queryselectorall (' img '). length; i++) {
Document.queryselectorall (' img ') [I].addeventlistener (' click ', Function (e) {
E.preventdefault ();
})
}
</script>

H5 Music Auto Play ios//no Android phone pictures click

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.