[英]Auto Play HTML5 Audio Element & Animation
I am working with a code that controls a very basic html5 player with animated elements. 我正在使用控制具有动画元素的非常基本的html5播放器的代码。 As is, the code starts the audio and the animation when clicked. 照原样,代码在单击时会启动音频和动画。 I would like for the audio and animation to begin automatically as soon as the page loads. 我希望音频和动画在页面加载后立即自动开始。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!
$( document ).ready(function() {
$('.spinner-wrap').click(function() {
var $this = $(this),
audio = $this.siblings('audio')[0],
bpm = Number($this.siblings('audio').data('bpm'))
pulse = (60/bpm)*1000;
if (audio.paused === false) {
audio.pause();
audio.currentTime = 0;
$this.removeClass('playing');
clearInterval(intervals);
}
else {
audio.play();
$this.addClass('playing');
}
function pulsing() {
$this.addClass('pulse');
setTimeout(function() {
$this.removeClass('pulse');
}, pulse-100);
}
});
});
I suggest you use the autoplay attribute of the audio tag, like so: 我建议您使用音频标签的自动播放属性,如下所示:
<audio autoplay>
<source src="ogg.ogg" type="audio/ogg">
<source src="mp3.mp3" type="audio/mpeg">
Sorry, no audio
</audio>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.