简体   繁体   English

向视频元素添加/删除类

[英]Add/remove class to video element

I'm working on a kiosk-style web page to display a menu of options. 我正在使用信息亭风格的网页来显示选项菜单。 Clicking on a title opens a fullscreen video which then closes back to the menu when the video ends. 单击标题可打开全屏视频,然后在视频结束时关闭菜单。

To keep the page clean, I'd like to hide the video element until the video is actually called by a click. 为了保持页面整洁,我想隐藏video元素,直到单击真正调用video为止。 I did this with a CSS class. 我是通过CSS类完成此操作的。 The video opens fullscreen and when finished, closes and adds the hide class again. 视频将全屏打开,完成后将关闭并再次添加hide类。

Working script 工作脚本

$(document).ready(function() {
  $('.cell').on('click', function() {
    var element = this.getElementsByTagName('video');
    var m = element[0].getAttribute('id');

    console.log(m);
    var v = document.getElementById(m);
    if (v.webkitRequestFullscreen) {
      v.className = "";
      v.webkitRequestFullscreen();
    }
    v.play();

    $("#" + m).on("ended", function() {
      this.webkitExitFullscreen();
      this.className = "hide";
    });
  })
})

I'm running into a problem of the video not hiding if the user exits full screen video on their own. 如果用户自行退出全屏视频,我会遇到视频无法隐藏的问题。 I tried using $("#" + m).on("ended" || "resize", function()... based on the HTML5 video API, but that didn't work. I'd also considered disabling clicks or overlaying a full-screen div to grab any clicks and force the video to play all the way through, but that seems shady to me. Any ideas on how to approach this? 我尝试使用基于HTML5视频API的$("#" + m).on("ended" || "resize", function()... ,但这没有用。我还考虑过禁用点击或在全屏div上叠加以获取所有点击,并强制视频一直播放,但这对我来说似乎很可疑。

Here's a CodePen demo of the content and script 这是内容和脚本的CodePen演示

Space separated list: 空格分隔的列表:

$("#" + m).on("ended resize"

To make it work you might need this trick: How to detect DIV's dimension changed? 要使其正常工作,您可能需要以下技巧: 如何检测DIV的尺寸已更改?

Update: I was able to catch the fullscreen event: 更新:我能够捕捉到全屏事件:

$(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e){
    console.log("fullscreen change");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM