zoukankan      html  css  js  c++  java
  • JS实现全屏和退出全屏

    这里实现的全屏和退出全屏是模仿按下F11。

    1.全屏

     1 function fullScreen(){
     2     var el = document.documentElement;
     3     var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
     4 
     5     //typeof rfs != "undefined" && rfs
     6     if (rfs) {
     7         rfs.call(el);
     8     }
     9     else if (typeof window.ActiveXObject !== "undefined") {
    10         //for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏
    11         var wscript = new ActiveXObject("WScript.Shell");
    12         if (wscript != null) {
    13             wscript.SendKeys("{F11}");
    14         }
    15     }
    16 }

    2.退出全屏

     1 function exitScreen(){
     2     var el = document;
     3     var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen;
     4 
     5     //typeof cfs != "undefined" && cfs
     6     if (cfs) {
     7         cfs.call(el);
     8     }
     9     else if (typeof window.ActiveXObject !== "undefined") {
    10         //for IE,这里和fullScreen相同,模拟按下F11键退出全屏
    11         var wscript = new ActiveXObject("WScript.Shell");
    12         if (wscript != null) {
    13             wscript.SendKeys("{F11}");
    14         }
    15     }
    16 }

     3.当然了为了实现全屏效果一般还得添加一个类

    1 .full{
    2     position: fixed!important;
    3     z-index: 10000;
    4      100%!important;
    5     height: 100%!important;
    6     top: 0;
    7     left: 0;
    8 }
  • 相关阅读:
    正则表达式学习网站
    Longest Substring Without Repeating Characters
    保留小数点后几位数字
    ReentrantLock和synchronized的区别随笔
    范型 小编
    两个线程交替打印字符串
    Gray Code
    Ajax
    堆排序
    Clone Graph
  • 原文地址:https://www.cnblogs.com/qxp140605/p/11851404.html
Copyright © 2011-2022 走看看