【问题标题】:How to disable click and double click controls for a video in Firefox?如何在 Firefox 中禁用视频的单击和双击控件?
【发布时间】:2016-08-31 23:05:34
【问题描述】:

我有一个视频 (<video id="video" controls src="foo.webm"></video>),通过这个视频我有一个 onclickondblclick 集。在 Chrome 上这工作正常,但在 Firefox 上,他们的“点击切换播放状态”和“双击全屏”会干扰我设置的代码。有没有办法从 Javascript 中禁用这些“功能”?

我已经尝试过event.preventDefault()return false,但这些对ondblclick 根本不起作用,并且部分适用于onclick。部分工作,这意味着他们完全禁用所有控件,您甚至无法单击视频左下方的播放/暂停按钮来播放/暂停它。

HTML

<div class="videocontainer">
    <div class="close">X</div>
    <video id="video" controls src="foo.webm"></video>
</div>

JavaScript

var video = document.getElementById('videocontainer');

video.onclick = function(ev) {

    ev.preventDefault(); //Disables all click events, including play/pause button
    if (ev.target.getAttribute('class') === close) closeVideo(); //if you clicked the close button it will close the video
    return false;        //Disables all click events, including play/pause button

};

video.ondblclick = function(ev) {

    ev.preventDefault(); //doesn't change anything
    if (ev.target.nodeName.toLowerCase() === 'video') popoutVideo();  //if you double clicked the video itself it will make the video fixed at the bottom right of the screen
    return false;        //doesn't change anything

};

【问题讨论】:

  • 您可以隐藏原生控件并提供自己的控件。
  • @Oriol 我尽量避免这样做
  • 那么你可以使用点击的坐标来判断一个控件是否被点击了,但这并不可靠。

标签: javascript firefox


【解决方案1】:

只是我添加了 controlsList="nofullscreen" 属性。 &lt;video id="vd" src="video.mp4" disablePictureInPicture controls controlsList="nofullscreen"&gt;&lt;/video&gt;

【讨论】:

    猜你喜欢
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 2021-06-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多