美文网首页
H5游戏之中方大和缩小屏幕的方法

H5游戏之中方大和缩小屏幕的方法

作者: 90后的晨仔 | 来源:发表于2017-10-17 21:43 被阅读6次

    方法一:

    //全屏
        var docElm = document.documentElement;
        //W3C
        if(docElm.requestFullscreen) {
          docElm.requestFullscreen();
        }
    
        //FireFox
        else if(docElm.mozRequestFullScreen) {
          docElm.mozRequestFullScreen();
        }
    
        //Chrome等
        else if(docElm.webkitRequestFullScreen) {
          docElm.webkitRequestFullScreen();
        }
    
        //IE11
        else if(elem.msRequestFullscreen) {
          elem.msRequestFullscreen();
        }
        
        
        -----------
        
        //退出全屏
        
            //W3C
        if (document.exitFullscreen) {
          document.exitFullscreen();
        }
        //FireFox
        else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        }
        //Chrome等
        else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        }
        //IE11
        else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
    
    

    方法二:

    //全屏
    function requestFullScreen(element) {
      // 判断各种浏览器,找到正确的方法
    var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
    if (requestMethod) {
      requestMethod.call(element);
    } else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
    var wscript = new ActiveXObject("WScript.Shell");
    if (wscript !== null) {
            wscript.SendKeys("{F11}");
                        }
                    }
                }
    
    
    //退出全屏 
        function exitFull() {
                    // 判断各种浏览器,找到正确的方法
      var exitMethod = document.exitFullscreen || //W3C
          document.mozCancelFullScreen || //Chrome等
          document.webkitExitFullscreen || //FireFox
          document.webkitExitFullscreen; //IE11
        if (exitMethod) {
         exitMethod.call(document);
          } else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
        wscript.SendKeys("{F11}");
            }
        }
    }
    
    
    

    相关文章

      网友评论

          本文标题:H5游戏之中方大和缩小屏幕的方法

          本文链接:https://www.haomeiwen.com/subject/sqyjuxtx.html