HTML5 video播放器全屏(fullScreen)方法實(shí)例
來源:易賢網(wǎng) 閱讀:8225 次 日期:2016-07-09 11:41:26
溫馨提示:易賢網(wǎng)小編為您整理了“HTML5 video播放器全屏(fullScreen)方法實(shí)例”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了HTML5 video播放器全屏(fullScreen)方法實(shí)例,本文直接給出一個(gè)完整代碼實(shí)例,需要的朋友可以參考下

首先來說,這個(gè)標(biāo)題具有誤導(dǎo)性,但這樣設(shè)置改標(biāo)題也是主要因?yàn)関ideo使用的比較多

在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 div.videobox{

width: 400px;

height: 320px;

margin: 100px auto;

background-color:#000;

}

body div.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>

<div 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>

</div>

<script type="text/javascript">

//反射調(diào)用

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;

};

//進(jìn)入全屏

function launchFullscreen(element) 

{

//此方法不可以在異步任務(wù)中執(zhí)行,否則火狐無法全屏

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>

更多信息請查看網(wǎng)頁制作
易賢網(wǎng)手機(jī)網(wǎng)站地址:HTML5 video播放器全屏(fullScreen)方法實(shí)例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)