简体   繁体   English

使html5视频全屏显示

[英]making html5 video to fullscreen

I have a custome HTML5 Video player, where in the HTML Page there is a video tag and another DIV tag where i have put the controls. 我有一个自定义HTML5视频播放器,在HTML页面中有一个视频标签和另一个放置了控件的DIV标签。 The Control DIV has play button,Pause button, Fullscreen button etc. Now i am trying to make the video full screen on the click of the full screen button. Control DIV具有播放按钮,暂停按钮,全屏按钮等。现在,我试图通过单击全屏按钮使视频全屏显示。 I have written the code making the use of requestFullscreen(). 我已经编写了使用requestFullscreen()的代码。 This code is not throwing any error but its neither working. 这段代码没有抛出任何错误,但是没有任何作用。 Could someone please tell me where i am going wrong?? 有人可以告诉我我要去哪里错吗?

var controls = {
video: $("#player"),  //this is the video element
fullscreen: $("#fullscreen")  //This is the fullscreen button.
};

controls.fullscreen.click(function(){
var elem = controls.fullscreen;
if (elem.requestFullscreen) {
    controls.video.requestFullscreen();
} else if (elem.mozRequestFullScreen) {
    controls.video.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
    controls.video.webkitRequestFullscreen();
}
});

controls.fullscreen and controls.video are both jQuery objects, not DOM elements. controls.fullscreencontrols.video都是jQuery对象,而不是DOM元素。 You want the elements inside the jQuery objects, which you can get with .get : 您需要jQuery对象中的元素,可以通过.get获得:

var controls = {
    video: $("#player").get(0),  //this is the video element
    fullscreen: $("#fullscreen").get(0)  //This is the fullscreen button.
};

jQuery objects don't have a requestFullscreen property, so none of your if statement were running (and if they had run, video.requestFullscreen wold have failed). jQuery对象没有requestFullscreen属性,因此您的if语句均未运行(如果已运行, video.requestFullscreen wold将会失败)。

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

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