jQuery HTML5 视频播放和暂停触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14177491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:19:35  来源:igfitidea点击:

HTML5 video play and pause triggering

jqueryhtml5-video

提问by itsme

I'm not able to trigger video play and pause events. I'm trying with:

我无法触发视频播放和暂停事件。我正在尝试:

<script type="text/javascript">
    $(function(){
        $(document).delegate('#play','click',function(){
            $('.video')[0].play();
        });
        $(document).delegate('#video-close','click',function(){
            $('.video')[0].pause();
        });
    });
</script>

<div class="video centered-content">
    <a class="circle-canvas close-video" href="javascript:void(0)" id="video-close">X</a>
    <video width="63%" height="80%" id="ourvideo" controls>
        <source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.mp4">
        <source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.ogv">
        <source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.webm">
    </video>
</div>
<a class="circle-canvas close-video" href="javascript:void(0)" id="play" >play</a>

Any suggestion?

有什么建议吗?

回答by undefined

You are selecting the div element that doesn't have play/pausemethod. Change:

您正在选择没有play/pause方法的 div 元素。改变:

$('.video')[0].play(); 

to:

到:

$('#ourvideo')[0].play();