TA的每日心情 | 奋斗 2024-11-24 15:47 |
---|
签到天数: 804 天 [LV.10]以坛为家III
管理员
- 积分
- 726782
|
- 首先, 在html中定义audio 标签的 autoplay属性
-
<audio id="musicStar" src="文件路径" autoplay="true" preload="auto" loop="loop"></audio>
- 其次,在body结尾处添加重定义的audioAutoPlay方法
-
function audioAutoPlay(id){ var audio = document.getElementById(id); var play = function(){ audio.play(); audio.pause(); document.removeEventListener("touchstart",play, false); }; audio.play(); document.addEventListener("touchstart",play, false); }
- 最后,需要在页头微信浏览器准备好以后,调用 audioAutoPlay方法
-
document.addEventListener("WeixinJSBridgeReady", function () { audioAutoPlay('musicStar');
-
综合所有
-
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,shrink-to-fit=no"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style"> <meta content="telephone=no" name="format-detection"> <meta name="msapplication-tap-highlight" content="no"> <script>
|
|