• JavaScript多个音频audio标签或者多个视频video,点击其中一个播放时,其他的停止播放


    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>一个页面中有多个音频audio标签,怎样在点击其中一个播放时,其他的停止播放</title>
    </head>
    
    <body>
        <audio src="http://www.ytmp3.cn/down/49366.mp3" controls></audio>
        <audio src="http://www.ytmp3.cn/down/49382.mp3" controls></audio>
        <audio src="http://www.ytmp3.cn/down/49369.mp3" controls></audio>
        <script type="text/javascript">
        // 获取所有audios
        var audios = document.getElementsByTagName("audio");
        // 暂停函数
        function pauseAll() {
            var self = this;
            [].forEach.call(audios, function(i) {
                // 将audios中其他的audio全部暂停
                i !== self && i.pause();
            })
        }
        // 给play事件绑定暂停函数
        [].forEach.call(audios, function(i) {
            i.addEventListener("play", pauseAll.bind(i));
        })
        </script>
    </body>
    
    </html>

     多个视频:

    // 视频点击播放/暂停
                    var videoAll = $(".J_catVideo");
                    videoAll.on("click",function(){
                        var cindex = videoAll.index(this);
                        videoAll.each(function (i) {
                            var video = $(this).find('video')[0];
                            if (i == cindex) {
                                if (video.paused) {
                                    $(this).find(".J_videoPic").hide();
                                    video.play();
                                } else {
                                    $(this).find(".J_videoPic").show();
                                    video.pause();
                                }
                            }else{
                                if (!video.paused) {
                                    $(this).find(".J_videoPic").show();
                                    video.pause();
                                }
                            }
                        })
                    })
  • 相关阅读:
    STDMETHOD (转)
    DirectX中的纹理映射相关技术 (转)
    (转)清空std::stringstream,联系到stream的clear()和清空
    (转载)MultiAnimation
    (转)SkyBox
    [转载]漫谈游戏中的阴影技术
    反射矩阵计算
    (转)COM组件里的AddRef()
    LINQ简记(2):重要概念
    继续聊WPF——自定义命令
  • 原文地址:https://www.cnblogs.com/huanghuali/p/9335537.html
Copyright © 2020-2023  润新知