Html Html5 全屏视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6039909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Html5 Full screen video
提问by Sahar
Is there any way to do this? I wan to play video in full screen. Without browser. setting width:100%; height:100%;
keep browser visible yet
有没有办法做到这一点?我想全屏播放视频。没有浏览器。设置width:100%; height:100%;
保持浏览器可见
回答by Mohsen
No, there is no way to do this yet. I wish they add a future like this in browsers.
不,目前还没有办法做到这一点。我希望他们在浏览器中添加这样的未来。
EDIT:
编辑:
Now there is a Full Screen APIfor the webYou can requestFullscreen
on an Video or Canvas element to ask user to give you permisions and make it full screen.
现在有一个用于网络的全屏 API您可以requestFullscreen
在 Video 或 Canvas 元素上要求用户授予您权限并使其全屏显示。
Let's consider this element:
让我们考虑这个元素:
<video controls id="myvideo">
<source src="somevideo.webm"></source>
<source src="somevideo.mp4"></source>
</video>
We can put that video into fullscreen mode with script like this:
我们可以使用如下脚本将该视频置于全屏模式:
var elem = document.getElementById("myvideo");
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
回答by Montaser
From CSS
来自 CSS
video {
position: fixed; right: 0; bottom: 0;
min-width: 100%; min-height: 100%;
width: auto; height: auto; z-index: -100;
background: url(polina.jpg) no-repeat;
background-size: cover;
}
回答by Vishnu
All hail HTML5 _/\_
万岁 HTML5 _/\_
var videoElement = document.getElementById('videoId');
videoElement.webkitRequestFullScreen();
回答by Tim Moses
Here is a very simple way (3 lines of code) using the Fullscreen APIand RequestFullscreenmethod that I used, which is compatible across all popular browsers:
这是使用我使用的Fullscreen API和RequestFullscreen方法的一种非常简单的方法(3 行代码),它兼容所有流行的浏览器:
var elem = document.getElementsByTagName('video')[0];
var fullscreen = elem.webkitRequestFullscreen || elem.mozRequestFullScreen || elem.msRequestFullscreen;
fullscreen.call(elem); // bind the 'this' from the video object and instantiate the correct fullscreen method.
回答by JrMatrix
You can do it with jQuery.
你可以用 jQuery 做到这一点。
I have my video and controls in their own <div>
like this:
我有自己的视频和控件,<div>
如下所示:
<div id="videoPlayer" style="width:520px; -webkit-border-radius:10px; height:420px; background-color:white; position:relative; float:left; left:25px; top:55px;" align="center">
<video controls width="500" height="400" style="background-color:black; margin-top:10px; -webkit-border-radius:10px;">
<source src="videos/gin.mp4" type="video/mp4" />
</video>
<script>
video.removeAttribute('controls');
</script>
<div id="vidControls" style="position:relative; width:100%; height:50px; background-color:white; -webkit-border-bottom-left-radius:10px; -webkit-border-bottom-right-radius:10px; padding-top:10px; padding-bottom:10px;">
<table width="100%" height="100%" border="0">
<tr>
<td width="100%" align="center" valign="middle" colspan="4"><input class="vidPos" type="range" value="0" step="0.1" style="width:500px;" /></td>
</tr>
<tr>
<td width="100%" align="center" valign="middle"><a href="javascript:;" class="playVid">Play</a></td>
<td width="100%" align="center" valign="middle"><a href="javascript:;" class="vol">Vol</a></td>
<td width="100%" align="left" valign="middle"><p class="timer"><strong>0:00</strong> / 0:00</p></td>
<td width="100%" align="center" valign="middle"><a href="javascript:;" class="fullScreen">Full</a></td>
</tr>
</table>
</div>
</div>
And then my jQuery for the .fullscreenclass is:
然后我的.fullscreen类的jQuery是:
var fullscreen = 0;
$(".fullscreen").click(function(){
if(fullscreen == 0){
fullscreen = 1;
$("video").appendTo('body');
$("#vidControls").appendTo('body');
$("video").css('position', 'absolute').css('width', '100%').css('height', '90%').css('margin', 0).css('margin-top', '5%').css('top', '0').css('left', '0').css('float', 'left').css('z-index', 600);
$("#vidControls").css('position', 'absolute').css('bottom', '5%').css('width', '90%').css('backgroundColor', 'rgba(150, 150, 150, 0.5)').css('float', 'none').css('left', '5%').css('z-index', 700).css('-webkit-border-radius', '10px');
}
else
{
fullscreen = 0;
$("video").appendTo('#videoPlayer');
$("#vidControls").appendTo('#videoPlayer');
//change <video> css back to normal
//change "#vidControls" css back to normal
}
});
It needs a little cleaning up as I'm still working on it but that should work for most browsers as far as I can see.
它需要一些清理,因为我仍在研究它,但据我所知,这应该适用于大多数浏览器。
Hope it helps!
希望能帮助到你!
回答by Raathigesh
You can use html5 video player which has full screen playback option.
This is a very good html5 player to have a look.
http://sublimevideo.net/
您可以使用具有全屏播放选项的 html5 视频播放器。这是一个非常好的html5播放器来看看。
http://sublimevideo.net/
回答by Jat
if (vi_video[0].exitFullScreen) vi_video[0].exitFullScreen();
else if (vi_video[0].webkitExitFullScreen) vi_video[0].webkitExitFullScreen();
else if (vi_video[0].mozExitFullScreen) vi_video[0].mozExitFullScreen();
else if (vi_video[0].oExitFullScreen) vi_video[0].oExitFullScreen();
else if (vi_video[0].msExitFullScreen) vi_video[0].msExitFullScreen();
else { vi_video.parent().append(vi_video.remove()); }