• 查看,设置,设备的 竖屏-横屏模式 screen.orientation


    <body>
      <div id="doc"></div>
      <div id="model"></div>
      <script>
        let a = 0;
      if ('orientation' in screen) {
        document.getElementById('doc').textContent = `屏幕旋转了${a}次.`;
        document.getElementById('model').textContent = `当前为${screen.orientation.type}模式!`;
    
        screen.orientation.addEventListener('change', function () {// 监听屏幕的旋转
          a++;
          document.getElementById('doc').textContent = `屏幕旋转了${a}次.`;
          if (screen.orientation.type.startsWith('landscape')) {
            document.getElementById('model').textContent = `当前为横屏模式!`;
          } else {
            document.getElementById('model').textContent = `当前为纵向模式!`;
          }
        });
      }
      </script>
    </body>
    

    screen.orientation.lock 开发者主动切换 landscape 和 portrait 模式

    对应的 screen.orientation.unlock();

    
    <!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->
    <!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]-->
    <!--[if IE 8]><html class="no-js lt-ie9"><![endif]-->
    <!--[if gt IE 8]><!-->
    <html class="no-js">
    <!--<![endif]-->
    <html lang="zh-cmn-Hans">
    
    <head>
      <meta charset="utf-8">
      <title>video 全屏体验</title>
      <link rel="shortcut icon" type="image/ico" href="" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <!--移动端视图-->
      <meta name="renderer" content="webkit" />
      <meta name="keywords" content="ajanuw" />
      <!--关键词-->
      <meta name="description" content="ajanuw, b,c" />
      <!--网站内容描述-->
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
      <meta http-equiv="Pragma" content="no-cache" />
      <!--禁止浏览器从本地计算机的缓存中访问页面内容-->
      <meta http-equiv="Window-target" content="_top" />
      <!--强制页面在当前窗口以独立页面显示-->
      <meta http-equiv="content-Type" content="text/html;charset=utf-8" />
      <!--显示字符集的设定-->
      <meta http-equiv="Content-Language" content="zh-cn" />
      <!--显示语言的设定-->
      <meta http-equiv="imagetoolbar" content="false" />
      <!--指定是否显示图片工具栏,false不显示,true显示-->
      <link rel="icon" sizes="192x192" href="https://pic.cnblogs.com/avatar/1053296/20171128213246.png" />
      <link rel="apple-touch-icon" href="https://pic.cnblogs.com/avatar/1053296/20171128213246.png" />
      <meta name="msapplication-square310x310logo" content="https://pic.cnblogs.com/avatar/1053296/20171128213246.png" />
      <meta name="theme-color" content="#ff4081" />
      <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
      <!-- Chrome, Firefox OS and Opera -->
      <link rel="apple-touch-startup-image" href="https://pic.cnblogs.com/avatar/1053296/20171128213246.png" />
      <style>
        .full-img {
          max- 100%;
        }
      </style>
    </head>
    
    <body>
      <!--[if lt IE 8]>  <h3>请升级你的浏览器,或更换主浏览器!!!</h3>  <![endif]-->
      <img class="full-img" src="http://per.kelantu.com/photos/1515232896-FnIf9c57Hf1-l7DUdBwlXdN1bcLv-orij0?e=3153600000&token=CT86R8zZYVXDyHWEWFoMX4pz0ksOzxtKCaC80si4:HcaTgLGmJ6IbOt_d9ZGOQIqtv6g="
        alt="">
      <div class="doc"></div>
      <script>
        let img = document.querySelector('.full-img');
        img.addEventListener('click', function (e) {
          if (document.requestFullscreen) {
            // 存在全屏 元素就退出全屏
            document.exitFullscreen();
          } else {
            requestFullscreenImage();
            lockScreenInLandscape();
          }
        }, false);
    
        function requestFullscreenImage() {
          if (img.requestFullscreen) {
            img.requestFullscreen();
          } else {
            img.webkitRequestFullscreen();
          }
        }
    
        function lockScreenInLandscape() {
          if (!('orientation' in screen)) {
            return;
          }
    
          // 判断当前 设备是 竖屏还是 横屏
          // portrait 竖屏
          // landscape 横屏
          if (matchMedia('(orientation: portrait) and (max-device- 768px)').matches) {
            // 竖屏就变 横屏
            screen.orientation.lock('landscape').then(function () {
              setTimeout(()=>{
                screen.orientation.unlock();
                // document.exitFullscreen();
                document.webkitExitFullscreen()
              }, 2000);
            });
          }
        }
      </script>
    </body>
    
    </html>
    
  • 相关阅读:
    P1128 [HNOI2001]求正整数
    zabbix-server端监控MySQL服务
    对服务器磁盘、CPU、内存使用状态,设置163邮件告警
    JDK8 的FullGC 之 metaspace
    JDK8-废弃永久代(PermGen)迎来元空间(Metaspace)
    JVM的方法区和永久带是什么关系?
    如何使用start with connect by prior递归用法
    JVM原理讲解和调优
    jvm 性能调优工具之 jstat
    记一次HBase内存泄漏导致RegionServer挂掉问题
  • 原文地址:https://www.cnblogs.com/ajanuw/p/8409350.html
Copyright © 2020-2023  润新知