获取html 5视频以全屏模式自动打开 [英] Get html 5 video to automatically open in fullscreen mode

查看:613
本文介绍了获取html 5视频以全屏模式自动打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地使用HTML 5视频标记和jQuery以全屏模式打开视频以响应事件(click,keypress)。如何在页面加载时全屏打开视频而不是onclick?任何帮助,将不胜感激。非常感谢!

I succeeded in getting a video to open in fullscreen mode in response to events (click, keypress) using the HTML 5 video tag and jQuery. How do I get the video to open in fullscreen on page load instead of onclick? Any help would be appreciated. Many thanks!

我的HTML:

    <div id="video_container>
       <video id="video1" width="1280" height="720" controls autoplay>
          <source src="videos/ballet.mp4" type="video/mp4">
          <source src="videos/ballet.webm" type="video/webm">
          <source src="videos/ballet.ogv" type="video/ogg">
       </video>
    </div>

我的JavaScript:

My JavaScript:

$(document).ready(function(){     
      $('#video1').bind("playing", function(){

        var elem = document.getElementById("video1");
        if (elem.requestFullscreen) {
          elem.requestFullscreen();
        } else if (elem.mozRequestFullScreen) {
          elem.mozRequestFullScreen();
        } else if (elem.webkitRequestFullscreen) {
          elem.webkitRequestFullscreen();
        }
      });

      $('#video1').bind("ended", function(){ 
        $("#video_container").hide();
      });
 });


推荐答案

听起来你不能把视频全屏放到页面加载,至少不适用于webkit浏览器。根据Safari开发人员库:

Sounds like you can't make the video fullscreen on page load, at least not for webkit browsers. According to the Safari Developer Library:


只有在响应
a用户操作时才能调用webkitEnterFullscreen()方法,例如单击按钮。例如,你不能调用
webkitEnterFullscreen()来响应加载事件。

The webkitEnterFullscreen() method can be invoked only in response to a user action, such as clicking a button. You cannot invoke webkitEnterFullscreen() in response to a load event, for example.

这里的全文: https://developer.apple.com/library/safari/ documentation / audiovideo / conceptual / using_html5_audio_video / controllingmediawithjavascript / controllingmediawithjavascript.html

这篇关于获取html 5视频以全屏模式自动打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆