admin管理员组文章数量:1399994
I have 4 <audio>
tags on a page. The client has requested that each snippet of audio be available linearly.
i.e. First available, rest disabled until finished playing, then second bees available etc.. etc..
Additionally, they've requested that the audio bars remain visible on screen (I was just going to add them dynamically) just not 'active'.
So the question is: How do I disable an audio tag when the disabled
attribute ( <audio disabled>
) doesn't exist..
Thanks in advance.
Update: Even a CSS, JS or JQuery answer would be appreciated... All I want to do is mimic a disabled button but for html audio.
I have 4 <audio>
tags on a page. The client has requested that each snippet of audio be available linearly.
i.e. First available, rest disabled until finished playing, then second bees available etc.. etc..
Additionally, they've requested that the audio bars remain visible on screen (I was just going to add them dynamically) just not 'active'.
So the question is: How do I disable an audio tag when the disabled
attribute ( <audio disabled>
) doesn't exist..
Thanks in advance.
Update: Even a CSS, JS or JQuery answer would be appreciated... All I want to do is mimic a disabled button but for html audio.
Share Improve this question edited Jan 20, 2015 at 0:09 Zze asked Jan 19, 2015 at 22:57 ZzeZze 18.9k14 gold badges95 silver badges125 bronze badges2 Answers
Reset to default 6You can also disable an audio tag if you add style="pointer-events:none"
to it…
I am assuming the html to be something like:
<audio src='...' controls id='audio1'></audio>
<audio src='...' controls id='audio2'></audio>
<audio src='...' controls id='audio3'></audio>
<audio src='...' controls id='audio4'></audio>
then my JQuery solution would be:
var audios = ['audio1', 'audio2', 'audio3', 'audio4'];
var canPlay = 0;
$('audio').each(function(){
this.addEventListener('play', function(){
if(this.id!=audios[canPlay]){
this.pause();
this.currentTime = 0;
}
});
this.addEventListener('ended', function(){
canPlay = (canPlay + 1) % audios.length;
});
});
本文标签: javascriptDisable HTML5 AudioStack Overflow
版权声明:本文标题:javascript - Disable HTML5 Audio - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744175255a2593969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论