html5 video ie全屏

发布网友 发布时间:2022-04-20 11:43

我来回答

5个回答

懂视网 时间:2022-04-20 04:08

这篇文章主要介绍了HTML5 video播放器全屏(fullScreen)方法实例,本文直接给出一个完整代码实例,需要的朋友可以参考下

首先来说,这个标题具有误导性,但这样设置改标题也是主要因为video使用的比较多

在html5中,全屏方法可以适用于很多html 元素,不仅仅是video

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>全屏问题</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta http-equiv="imagetoolbar" content="no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<style type="text/css">
*{
 padding: 0px;
 margin: 0px;
}

body p.videobox{
 width: 400px;
 height: 320px;
 margin: 100px auto;
 background-color:#000;
}

body p.videobox video.video
{
width: 100%;
 height: 100%;
}

:-webkit-full-screen {

}

:-moz-full-screen {

}

:-ms-fullscreen {

}

:-o-fullscreen {

}

:full-screen { 

}

:fullscreen {

}

:-webkit-full-screen video {
 width: 100%;
 height: 100%;
}
:-moz-full-screen video{
 width: 100%;
 height: 100%;
}
 </style>
</head>
<body>


<p id="videobox">

 <video controls="controls" preload="preload" id="video" poster="poster.jpg">
 <source src="./movie.ogg" type="video/ogg" />
 <source src="./movie.mp4" type="video/mp4" />
 <source src="./movie.webm" type="video/webm" />
 <object data="./movie.mp4" width="100%" height="100%">
 <embed width="100%" height="100%" src="./movie.swf" />
 </object>

 </video>
 <button id="fullScreenBtn">全屏</button>
</p>


<script type="text/javascript">

//反射調用
var invokeFieldOrMethod = function(element, method) 
{
 var usablePrefixMethod;
 ["webkit", "moz", "ms", "o", ""].forEach(function(prefix) {
 if (usablePrefixMethod) return;
 if (prefix === "") {
  // 无前缀,方法首字母小写
  method = method.slice(0,1).toLowerCase() + method.slice(1); 
 }
 var typePrefixMethod = typeof element[prefix + method];
 if (typePrefixMethod + "" !== "undefined") {
  if (typePrefixMethod === "function") {
  usablePrefixMethod = element[prefix + method]();
  } else {
  usablePrefixMethod = element[prefix + method];
  }
 }
 });

 return usablePrefixMethod;
};

//進入全屏
function launchFullscreen(element) 
 {
 //此方法不可以在異步任務中執行,否則火狐無法全屏
 if(element.requestFullscreen) {
 element.requestFullscreen();
 } else if(element.mozRequestFullScreen) {
 element.mozRequestFullScreen();
 } else if(element.msRequestFullscreen){ 
 element.msRequestFullscreen(); 
 } else if(element.oRequestFullscreen){
 element.oRequestFullscreen();
 }
 else if(element.webkitRequestFullscreen)
 {
 element.webkitRequestFullScreen();
 }else{

 var docHtml = document.documentElement;
 var docBody = document.body;
 var videobox = document.getElementById('videobox');
 var cssText = 'width:100%;height:100%;overflow:hidden;';
 docHtml.style.cssText = cssText;
 docBody.style.cssText = cssText;
 videobox.style.cssText = cssText+';'+'margin:0px;padding:0px;';
 document.IsFullScreen = true;

 }
 }
//退出全屏
 function exitFullscreen()
 {
 if (document.exitFullscreen) {
 document.exitFullscreen();
 } else if (document.msExitFullscreen) {
 document.msExitFullscreen();
 } else if (document.mozCancelFullScreen) {
 document.mozCancelFullScreen();
 } else if(document.oRequestFullscreen){
  document.oCancelFullScreen();
 }else if (document.webkitExitFullscreen){
 document.webkitExitFullscreen();
 }else{
 var docHtml = document.documentElement;
 var docBody = document.body;
 var videobox = document.getElementById('videobox');
 docHtml.style.cssText = "";
 docBody.style.cssText = "";
 videobox.style.cssText = "";
 document.IsFullScreen = false;
 }
 }
document.getElementById('fullScreenBtn').addEventListener('click',function(){
 launchFullscreen(document.getElementById('video')); 
 window.setTimeout(function exit(){
//檢查瀏覽器是否處於全屏
if(invokeFieldOrMethod(document,'FullScreen') || invokeFieldOrMethod(document,'IsFullScreen') || document.IsFullScreen)
{
exitFullscreen();
}
 },5*1000);
},false);

</script>
</body>

</html>

热心网友 时间:2022-04-20 01:16


//模拟F11

function F11key(){ 

//判断是否ie并进行相应的全屏

//requestFullScreen()

var navigatorName = "Microsoft Internet Explorer";    

if( navigator.appName == navigatorName ){    

//alert("ie")   

var WsShell = new ActiveXObject('WScript.Shell') 

WsShell.SendKeys('{F11}'); 

}else{   

var de = document.documentElement;

if (de.requestFullscreen) {

de.requestFullscreen();

} else if (de.mozRequestFullScreen) {

de.mozRequestFullScreen();

} else if (de.webkitRequestFullScreen) {

de.webkitRequestFullScreen();

}else if (de.msRequestFullscreen) {

de.msRequestFullscreen();

}

//alert("not ie")   

热心网友 时间:2022-04-20 02:34

开始播放自动全屏暂停自动还原
示例代码:
<video controls src="" width="250" height="250" onpause="width='要还原的宽度 ';height='要还原的高度'" onplaying="width='适合屏幕的宽度';height='适合屏幕的高度 '"></video>

热心网友 时间:2022-04-20 04:08

video{width:100%; height:100%;}

热心网友 时间:2022-04-20 06:00

自己写个js,网上有很多的例子,你可以看一下

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com