最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談javascript控制HTML5的全屏操控,瀏覽器兼容的問題

 更新時間:2016年10月10日 09:23:35   投稿:jingxian  
下面小編就為大家?guī)硪黄獪\談javascript控制HTML5的全屏操控,瀏覽器兼容的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

如果你想使一個元素在全屏模式下展現(xiàn) (比如說 <video>),你可以調(diào)用該元素的 requestFullscreen() 方法;這個方法在 Gecko 中的實現(xiàn)是 element.mozRequestFullScreen(),在 WebKit 中為 element.webkitRequestFullscreen()。

比如一個實例:

var elem = document.getElementById("myvideo");
if (elem.requestFullscreen) {
 elem.requestFullscreen();		//IE瀏覽器
} else if (elem.mozRequestFullScreen) {
 elem.mozRequestFullScreen();			//火狐瀏覽器
} else if (elem.webkitRequestFullscreen) {
 elem.webkitRequestFullscreen();			//谷歌瀏覽器
}

運行到這里,Gecko 與 WebKit 兩個實現(xiàn)中出現(xiàn)了一個值得注意的區(qū)別:Gecko 會為元素自動添加 CSS 使其伸展以便鋪滿屏幕: "width: 100%; height: 100%"。 WebKit 則不會這么做;它會讓全屏的元素以原始尺寸居中到屏幕中央,其余部分變?yōu)楹谏?。為了?WebKit 下也達到與 Gecko 同樣的全屏效果,你需要手動為元素增加 CSS 規(guī)則"width: 100%; height: 100%;":

function toggleFullScreen() {
 if (!document.fullscreenElement &&  // alternative standard method
   !document.mozFullScreenElement && !document.webkitFullscreenElement) { // current working methods
  if (document.documentElement.requestFullscreen) {
   document.documentElement.requestFullscreen();
  } else if (document.documentElement.mozRequestFullScreen) {
   document.documentElement.mozRequestFullScreen();
  } else if (document.documentElement.webkitRequestFullscreen) {
   document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  }
 } else {
  if (document.cancelFullScreen) {
   document.cancelFullScreen();
  } else if (document.mozCancelFullScreen) {
   document.mozCancelFullScreen();
  } else if (document.webkitCancelFullScreen) {
   document.webkitCancelFullScreen();
  }
 }
}

代碼首先檢查了 document 上的 fullscreenElement 屬性(也檢查了帶 -moz- 與 -webkit- 兩個前綴的)。如果該屬性為 null,則 document 當(dāng)前處于窗口模式,所以我們需要切換進全屏模式??梢酝ㄟ^調(diào)用 element.mozRequestFullScreen() 或者 webkitRequestFullscreen()來進入全屏模式,具體調(diào)用哪個還要看哪個方法可用。

如果已經(jīng)激活了全屏模式 (fullscreenElement 非空),我們調(diào)用 document.mozCancelFullScreen() 或 webkitCancelFullScreen(),同樣要依賴于我們使用了哪個瀏覽器。

以上就是小編為大家?guī)淼臏\談javascript控制HTML5的全屏操控,瀏覽器兼容的問題全部內(nèi)容了,希望大家多多支持腳本之家~

相關(guān)文章

最新評論

公安县| 永福县| 灌南县| 正定县| 松潘县| 平凉市| 诸城市| 湖南省| 内丘县| 哈尔滨市| 六盘水市| 保亭| 嘉善县| 宁阳县| 秭归县| 诸城市| 万载县| 晋宁县| 宝丰县| 章丘市| 南乐县| 贵溪市| 和林格尔县| 朝阳市| 泾源县| 汉阴县| 洛南县| 蓬安县| 蚌埠市| 南汇区| 新闻| 措勤县| 永靖县| 六安市| 连山| 油尖旺区| 工布江达县| 夹江县| 高邑县| 韶山市| 南投县|