zoukankan      html  css  js  c++  java
  • 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();
                                }
                            }
                        })
                    })
  • 相关阅读:
    activemq学习
    shell变量
    ext3文件系统目录限制问题
    linux性能优化cpu 磁盘IO MEM
    vs2010下编译osip2和eXosip2的4.0.0版的静态库及搭建开发环境
    samba的rpm包,只有tar.gz文件安装
    随记
    mount/umount系统调用
    不定参数的传递VA_LIST的用法
    samba服务器源码安装(非rpm)
  • 原文地址:https://www.cnblogs.com/huanghuali/p/9335537.html
Copyright © 2011-2022 走看看