我在一个页面上有 2 个音频实例。处理音频的播放和暂停不是问题。问题是当音频正在播放并且我单击另一个音频实例时,我无法通过图标修改让另一个音频实例停止播放
任何帮助将不胜感激:) 谢谢
$('section .play').click(function(){
var $this = $(this);
// starting audio
var audioID = "sound" + $(this).attr('id');
$this.toggleClass('active');
if($this.hasClass('active')){
$("#" + audioID).trigger('play');
} else {
$("#" + audioID).trigger('pause');
}
});
section {
display: block;
margin-bottom: 30px;
padding: 0 20px;
text-align: center;
width: 200px;
height: 200px;
position: relative;
}
section .btn {
background: #ccc;
border: 0 none;
cursor: pointer;
display: block;
height: 60px;
line-height: 60px;
position: absolute;
width: 200px;
z-index: 100;
bottom: 0;
text-align: center;
}
section .btn:after {
content: "play";
}
section .btn.active:after {
content: "pause";
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section><img src="https://unsplash.it/g/300?image=29" width="200" height="200" />
<p class="play btn" id="7"></p>
<p><audio id="sound7">
<source src="https://room1015.com/img/cms/MP3/Hanging-out-in-room-1015.mp3" type="audio/mpeg" />
</audio></p>
</section>
<section><img src="https://unsplash.it/g/300?image=29" width="200" height="200" />
<p class="play btn" id="6"></p>
<p><audio id="sound6">
<source src="https://room1015.com/img/cms/MP3/HOLLYROSE.mp3" type="audio/mpeg" />
</audio></p>
</section>
30秒到达战场
相关分类