zoukankan      html  css  js  c++  java
  • ipad方案

    let viewTimer = null
    
    function viewPort(userAgent, pageWidth) {
      let oView = document.getElementById('viewport')
      if (oView) {
        document.head.removeChild(oView)
      }
      if (!pageWidth) {
        // 手机页面设计图的宽度,宽度多少设置多少
        pageWidth = 375
      }
      let screenW = parseInt(window.screen.width)
      let scale = screenW / pageWidth
      if (/Android (d+.d+)/.test(userAgent)) {
        let creatMeta = document.createElement('meta')
        creatMeta.name = 'viewport'
        creatMeta.id = 'viewport'
        let version = parseFloat(RegExp.$1)
        if (version > 2.3) {
          creatMeta.content = 'width=' + pageWidth + ', initial-scale = ' + scale + ',user-scalable=1, minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', target-densitydpi=device-dpi'
        } else {
          creatMeta.content = '"width=' + pageWidth + ', target-densitydpi=device-dpi'
        }
        document.head.appendChild(creatMeta)
      } else {
        let creatMeta = document.createElement('meta')
        creatMeta.name = 'viewport'
        creatMeta.id = 'viewport'
        // 判断移动设备横屏竖屏
        if (window.orientation === '-90' || window.orientation === '90') {
          scale = window.screen.height / pageWidth
          creatMeta.content = 'width=' + pageWidth + ', initial-scale = ' + scale + ' ,minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', user-scalable=no, target-densitydpi=device-dpi'
        } else {
          creatMeta.content = 'width=' + pageWidth + ', initial-scale = ' + scale + ' ,minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', user-scalable=no, target-densitydpi=device-dpi'
        }
        document.head.appendChild(creatMeta)
      }
    }
    
    viewPort(navigator.userAgent)
    
    window.onresize = function () {
      clearTimeout(viewTimer)
      viewTimer = setTimeout(function () {
        viewPort(navigator.userAgent)
      }, 500)
    }
    require('./utils/ipad')
  • 相关阅读:
    linux 下spyder安装
    【C++】fill函数,fill与memset函数的区别
    【tensorflow使用笔记一】:安装linux下tensorflow环境的问题
    leetcode 49 字母异位词分组
    leetcode 1014. 在 D 天内送达包裹的能力
    【C++进阶:STL常见性质3】
    【C++进阶:STL常见性质2】
    【C++进阶:STL常见性质】
    【C++进阶:移位运算符的用法】
    面向对象之静态方法
  • 原文地址:https://www.cnblogs.com/ronle/p/11451370.html
Copyright © 2011-2022 走看看