在全屏播放HTML5视频时,自定义控件仍然适用吗?

tim*_*son 8 html5 fullscreen custom-controls html5-video

我已经为我的HTML5视频制作了自定义控件,但我不知道如何在全屏时使用CSS.

这是[网站]我基于我的控件.

在此网站上,您会注意到当您单击全屏按钮时,自定义控件会丢失,视频将恢复为默认<video>控件.

当你全屏时,有谁知道如何让这些自定义控件样式/ CSS仍然适用?

tim*_*son 14

我回答了我自己的问题,关键是自定义控件在<div>其中包含您要全屏拍摄的视频.在下面的代码中,这<div>称为"videoContainer".

这是我用来解决这个问题的链接. http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html

这是在webkit和mozilla浏览器中进入和退出全屏模式的JS代码:

var $video=$('video');
//fullscreen button clicked
$('#fullscreenBtn').on('click', function() {
$(this).toggleClass('enterFullscreenBtn');
    if($.isFunction($video.get(0).webkitEnterFullscreen)) {
              if($(this).hasClass("enterFullscreenBtn"))
                  document.getElementById('videoContainer').webkitRequestFullScreen();                          
              else 
              document.webkitCancelFullScreen();    
    }  
    else if ($.isFunction($video.get(0).mozRequestFullScreen)) {
              if($(this).hasClass("enterFullscreenBtn"))
                  document.getElementById('videoContainer').mozRequestFullScreen(); 
               else 
                  document.mozCancelFullScreen();   
    }
    else { 
           alert('Your browsers doesn\'t support fullscreen');
    }
});
Run Code Online (Sandbox Code Playgroud)

这是HTML:

<div id="videoContainer">
      <video>...<source></source>
      </video>
      <div> custom controls 
            <button>play/pause</button>
            <button id="fullscreenBtn" class="enterFullscreenBtn">fullscreen</button>
      </div>
</div>
Run Code Online (Sandbox Code Playgroud)

  • 好吧,我想我终于掌握了这一点.它是你全屏的容器,如果视频和自定义控件都在那个容器中,那么你就是好的.浏览器也会停止搞乱你,因为你没有把视频带到全屏,他们不需要跳进去,用他们糟糕的控制来挽救这一天. (3认同)