您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

利用浏览器全屏api实现js全屏_jquery

2026/1/23 8:18:26发布136次查看
复制代码 代码如下:
(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    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!);
}
复制代码 代码如下:
javascript启用全屏
点击我进入全屏模式
我是全屏区域的内容!
复制代码 代码如下:
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%;
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product