multiple audio html : auto stop other when current is playing with javascript

后端 未结 6 839
情深已故
情深已故 2020-12-13 02:58

I have 10 audio players with simple html audio tags on a html5 page. No jquery, no special audio js plugins, etc...

Does anyone has a simple script in js to pause al

6条回答
  •  执笔经年
    2020-12-13 03:20

    $("audio").on("play", function() {
        var id = $(this).attr('id');
    
        $("audio").not(this).each(function(index, audio) {
            audio.pause();
        });
    });
    
    $("video").on("play", function() {
        var id = $(this).attr('id');
    
        $("video").not(this).each(function(index, video) {
            video.pause();
        });
    });
    

提交回复
热议问题