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

首頁 > 語言 > JavaScript > 正文

利用瀏覽器全屏api實(shí)現(xiàn)js全屏

2024-05-06 16:00:10
字體:
供稿:網(wǎng)友
這篇文章主要介紹了利用瀏覽器全屏api實(shí)現(xiàn)js全屏的代碼示例,示例中使用了jquery,把這個(gè)庫的地址改成自己的,大家參考使用吧

復(fù)制代碼 代碼如下:


(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里面不能演示該功能!請點(diǎn)擊右下角的全屏查看!").show();
 }
});

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

復(fù)制代碼 代碼如下:


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

 <script type="text/javascript" src=jquery-1.8.3.min.js"></script>
 </head>
 <body>
  <button>點(diǎn)擊我進(jìn)入全屏模式</button>
  <div>
    <h1>
     我是全屏區(qū)域的內(nèi)容!
   </h1>
   <div>

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

復(fù)制代碼 代碼如下:


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%;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 铁岭县| 广宗县| 天祝| 德令哈市| 嫩江县| 红河县| 大余县| 平凉市| 泗水县| 贵州省| 潼南县| 花垣县| 济宁市| 石家庄市| 张家港市| 塔城市| 巴林右旗| 新巴尔虎右旗| 东辽县| 郑州市| 龙里县| 铁岭市| 呼玛县| 遵义市| 尖扎县| 巴林左旗| 霍林郭勒市| 东阿县| 浦东新区| 化州市| 隆回县| 荥经县| 五河县| 嘉义县| 菏泽市| 镇远县| 桃园市| 银川市| 新津县| 苏州市| 太湖县|