国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

利用瀏覽器全屏api實現js全屏

2019-11-20 21:14:33
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

(function () {
 var fullScreenApi = {
  supportsFullScreen : false,
  isFullScreen : function () {
   return false;
  },
  requestFullScreen : function () {},
  cancelFullScreen : function () {},
  fullScreenEventName : '',
  prefix : ''
 },
 browserPrefixes = 'webkit moz o ms khtml'.split(' ');

 // check for native support
 if (typeof document.cancelFullScreen != 'undefined') {
  fullScreenApi.supportsFullScreen = true;
 } else {
  // check for fullscreen support by vendor prefix
  for (var i = 0, il = browserPrefixes.length; i < il; i++) {
   fullScreenApi.prefix = browserPrefixes[i];

   if (typeof document[fullScreenApi.prefix + 'CancelFullScreen'] != 'undefined') {
    fullScreenApi.supportsFullScreen = true;

    break;
   }
  }
 }

 // update methods to do something useful
 if (fullScreenApi.supportsFullScreen) {
  fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';

  fullScreenApi.isFullScreen = function () {
   switch (this.prefix) {
   case '':
    return document.fullScreen;
   case 'webkit':
    return document.webkitIsFullScreen;
   default:
    return document[this.prefix + 'FullScreen'];
   }
  }
  fullScreenApi.requestFullScreen = function (el) {
   return (this.prefix === '') ? el.requestFullScreen() : el[this.prefix + 'RequestFullScreen']();
  }
  fullScreenApi.cancelFullScreen = function (el) {
   return (this.prefix === '') ? document.cancelFullScreen() : document[this.prefix + 'CancelFullScreen']();
  }
 }

 // jQuery plugin
 if (typeof jQuery != 'undefined') {
  jQuery.fn.requestFullScreen = function () {

   return this.each(function () {
    if (fullScreenApi.supportsFullScreen) {
     fullScreenApi.requestFullScreen(this);
    }
   });
  };
 }

 // export api
 window.fullScreenApi = fullScreenApi;
})();

$(function(){
 $("#fullScreenBtn").click(function(){
  $("#fullScreen").requestFullScreen();
 });

 if(window.top != self){
  $("#tip").text("iframe里面不能演示該功能!請點擊右下角的全屏查看!").show();
 }
});

if (!fullScreenApi.supportsFullScreen) {
 alert("您的破瀏覽器不支持全屏API哦,請換高版本的chrome或者firebox!");
}

復制代碼 代碼如下:

<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>javascript啟用全屏</title>

 <script id="jquery_183" type="text/javascript" class="library" src=jquery-1.8.3.min.js"></script>
 </head>
 <body>
  <button id="fullScreenBtn">點擊我進入全屏模式</button>
  <div id="fullScreen" class="fullScreen">
    <h1>
     我是全屏區域的內容!
   </h1>
   <div id="tip" style="display:none;">

   </div>
  </div>
 </body>
</html>

復制代碼 代碼如下:

body{
background:#fff;
}
button{
 border:1px solid #ccc;
 cursor:pointer;
  display:block;
  margin:auto;
  position:relative;
  top:100px;
}

.fullScreen{
 padding-top:10%;
 text-align:center;
 background: none repeat scroll 0 0 #FFFFFF;
}

/* Mozilla proposal (dash) */
.fullScreen:full-screen {
    width:100%;
    height:100%;
}

/* W3C proposal (no dash) */
.fullScreen:fullscreen {
    width:100%;
    height:100%;
}

/* currently working vendor prefixes */
.fullScreen:-webkit-full-screen, .fullScreen:-moz-full-screen {
    width:100%;
    height:100%;
}
:-webkit-full-screen{
width:100%;
    height:100%;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇源县| 潞西市| 黑水县| 扎鲁特旗| 铅山县| 巴东县| 黄石市| 盐津县| 丰顺县| 昆明市| 抚州市| 黄平县| 阿拉善右旗| 正安县| 盐山县| 穆棱市| 秦皇岛市| 临安市| 崇义县| 云梦县| 边坝县| 织金县| 虞城县| 潞城市| 夏河县| 枣庄市| 汾西县| 龙州县| 巴彦淖尔市| 呼和浩特市| 乐清市| 泰安市| 天水市| 黑山县| 五原县| 金昌市| 刚察县| 东光县| 玉林市| 崇信县| 涞源县|