• js实现元素全屏展示,退出全屏及判断是否是全屏


    HTML代码示例:
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style type="text/css">
          .wrap {
            margin: 0 auto;
            border: 1px solid red;
            text-align: center;
          }
          #content {
            margin: 0 auto;
            height: 500px;
             700px;
            background: #ccc;
            text-align: center;
            line-height: 500px;
          }
          /* 全屏时的样式 */
          /* #content:-webkit-full-screen {
            background-color: rgb(255, 255, 12);
          } */
        </style>
      </head>
      <body>
        <div class="wrap">
          <button id="btn">全屏</button>
          <div id="content">
            <h1>js控制页面的全屏展示和退出全屏显示</h1>
          </div>
        </div>
        <script>
          document.getElementById('btn').onclick = function () {
            var dom = document.getElementById('content')
            requestFullScreen(dom)
          }
          function requestFullScreen(element) {
            // 兼容谷歌、火狐、IE
            let requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen
            if (requestMethod) {
              requestMethod.call(element)
            } else if (window.ActiveXObject) {
              debugger
              let ActiveXObject = window.ActiveXObject
              var wscript = new ActiveXObject('WScript.Shell')
              if (wscript !== null) {
                wscript.SendKeys('{F11}')
              }
            }
          }
        </script>
      </body>
    </html>
     --------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    https://blog.csdn.net/u013240519/article/details/84035505  js实现全屏和退出全屏功能
     
    退出全屏:
            // 注意,这里的document就是文档中的document,不能修改,也就是直接复制下面的代码就能退出全屏
              let exitFullScreen = document.exitFullScreen || document.mozCancelFullScreen || document.webkitExitFullscreen || document.msExitFullscreen
              if (exitFullScreen) {
                exitFullScreen.call(document)
              }
     
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     

    判断当前是否已全屏

    如果element处于全屏模式则返回这个对象; 如果element当前未使用全屏模式,则返回值为null。
    function isFullscreen () {
    return document.fullscreenElement ||
    document.msFullscreenElement ||
    document.mozFullScreenElement ||
    document.webkitFullscreenElement || false;
    }
     
  • 相关阅读:
    根据用户输入的时间查询那天的数据
    动软 生成 linq相关DAO
    pdf 移除密码 去除水印 批量去除水印 编辑文字 批量替换文字
    利用OCR识别扫描的jpg、tif文件的文字
    jstat命令详解
    IDEA自动编译设置
    IntelliJ IDEA:Field injection is not recommended
    阿里巴巴Druid数据库连接池配置详解及使用
    com.mysql.jdbc.Driver和com.mysql.cj.jdbc.Driver的区别
    Java对元与分的金额的转换
  • 原文地址:https://www.cnblogs.com/shidawang/p/14150086.html
Copyright © 2020-2023  润新知