码迷,mamicode.com
首页 > 编程语言 > 详细

javascript 实现全屏

时间:2014-10-27 17:24:56      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   java   sp   div   on   

1 可以添加事件,全屏错误事件

2 IE11以上

3 chrome全屏需要设置元素的宽度、高度,否则显示的是缩略大小

GLOBAL.BigScreen = function(node)
{ 
  this._enable = false;
  this._node = null;
  var v_node = typeof node == "string" ? document.getElementById(node) : node;
  if(typeof(v_node) == "undefined" || v_node == null)
  {
     this._node = document;
  }else
  {
     this._node = v_node;
  }
  if (document.fullscreenEnabled ||document.webkitFullscreenEnabled ||document.mozFullScreenEnabled ||document.msFullscreenEnabled)
  {
      this._enable = true;
  }
}
GLOBAL.BigScreen.prototype.enable = function()
{
   return this._enable;
}

GLOBAL.BigScreen.prototype.isFullScreen = function()
{
   if(document.fullscreenElement ||document.webkitFullscreenElement ||document.mozFullScreenElement ||document.msFullscreenElement)
   {
      return true;
   }else
   {
      return false;
   }
}
GLOBAL.BigScreen.prototype.toggle = function()
{  
   if(this._enable == false)
   {
      this._defaultToFullScreen();
      return;
   }
   var req = null;
   if(this.isFullScreen())
   {
      req = this._node.exitFullscreen|| this._node.webkitExitFullscreen || this._node.mozCancelFullScreen || this._node.msExitFullscreen;
      req.call(this._node);  
  }else
  { 
   if(this._node.nodeName == "#document")
   {
       req = this._node.body.requestFullscreen || this._node.body.webkitRequestFullscreen || this._node.body.mozRequestFullScreen || this._node.body.msRequestFullscreen;
       req.call(this._node.body);
   }
   else
   {
       req = this._node.requestFullscreen || this._node.webkitRequestFullscreen || this._node.mozRequestFullScreen || this._node.msRequestFullscreen;
       req.call(this._node);
   }
  }
 
}


GLOBAL.BigScreen.prototype.addOnFullScreenError = function(handler,scope){
      if(this._enable == false)
          return  null;
      if (document.fullscreenEnabled) {
          return GLOBAL.Event.on(document,"fullscreenerror",handler,scope);
      } else if (document.webkitFullscreenEnabled) {
          return  GLOBAL.Event.on(document,"webkitfullscreenerror",handler,scope);
      } else if (document.mozFullScreenEnabled) {
          return GLOBAL.Event.on(document,"mozfullscreenerror",handler,scope);
      } else if (document.msFullscreenEnabled) {
          return GLOBAL.Event.on(document,"MSFullscreenError",handler,scope);
      } 
 }

 
GLOBAL.BigScreen.prototype.addOnFullscreenChange= function(handler,scope){
      if(this._enable == false)
          return;
      if (document.fullscreenEnabled) {
           GLOBAL.Event.on(document,"fullscreenchange",handler,scope);
       } else if (document.webkitFullscreenEnabled) {
           GLOBAL.Event.on(document,"webkitfullscreenchange",handler,scope);
       } else if (document.mozFullScreenEnabled) {
           GLOBAL.Event.on(document,"mozfullscreenchange",handler,scope);
       } else if (document.msFullscreenEnabled) {
            GLOBAL.Event.on(document,"MSFullscreenChange",handler,scope);
        } 
 }
 
GLOBAL.BigScreen.prototype._defaultToFullScreen = function()
{   
    if(this._enable)
      return;
    if (typeof window.ActiveXObject !== "undefined") {
    var wscript = new ActiveXObject("WScript.Shell");
    if (wscript !== null) {
      wscript.SendKeys("{F11}");
    }
  }
}

 

javascript 实现全屏

标签:style   blog   io   color   ar   java   sp   div   on   

原文地址:http://www.cnblogs.com/derekxxd/p/4054396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!