zoukankan      html  css  js  c++  java
  • 适配

    在一个项目中看到的移动端适配:

    !function (e, t) {
          console.log(t);
    
          function i() {
            var t = n.getBoundingClientRect().width;
            console.log(n.getBoundingClientRect());
            t / d > s && (t = s * d);
            var i = t / 7.5;
            n.style.fontSize = i + "px", c.rem = e.rem = i
          }
    
          var a, r = e.document, n = r.documentElement, o = r.querySelector('meta[name="viewport"]'),
            m = r.querySelector('meta[name="flexible"]'), l = r.querySelector('meta[name="max-width"]'), s = 1024, d = 0,
            p = 0, c = t.flexible || (t.flexible = {});
          if (o) {
            console.warn("将根据已有的meta标签来设置缩放比例");
            var u = o.getAttribute("content").match(/initial-scale=([d.]+)/);
            u && (p = parseFloat(u[1]), d = parseInt(1 / p))
          } else if (m) {
            var v = m.getAttribute("content");
            if (v) {
              var f = v.match(/initial-dpr=([d.]+)/), h = v.match(/maximum-dpr=([d.]+)/);
              f && (d = parseFloat(f[1]), p = parseFloat((1 / d).toFixed(2))), h && (d = parseFloat(h[1]), p = parseFloat((1 / d).toFixed(2)))
            }
          }
          if (l) {
            var g = l.getAttribute("content");
            g && (s = parseInt(g))
          }
          if (!d && !p) {
            var w = e.navigator.userAgent.match(/Android[Ss]+AppleWebkit/(d{3})/i),
              x = e.navigator.userAgent.match(/U3/((d+|.){5,})/i), b = x && parseInt(x[1].split(".").join(""), 10) >= 80,
              A = e.navigator.appVersion.match(/(iphone|ipad|ipod)/gi);
            e.navigator.appVersion.match(/OS 9_3/), e.devicePixelRatio;
            d = e.devicePixelRatio || 1, A || w && w[1] > 534 || b || (d = 1), p = 1 / d
          }
          if (n.setAttribute("data-dpr", d), !o) if (o = r.createElement("meta"), o.setAttribute("name", "viewport"), o.setAttribute("content", "width=device-width,initial-scale=" + p + ", maximum-scale=" + p + ", minimum-scale=" + p + ", user-scalable=no,user-scalable=0,viewport-fit=cover"), n.firstElementChild) n.firstElementChild.appendChild(o); else {
            var F = r.createElement("div");
            F.appendChild(o), r.write(F.innerHTML)
          }
          e.addEventListener("resize", function () {
            clearTimeout(a), a = setTimeout(i, 300)
          }, !1), e.addEventListener("pageshow", function (e) {
            e.persisted && (clearTimeout(a), a = setTimeout(i, 300))
          }, !1), i(), c.dpr = e.dpr = d, c.refreshRem = i, c.rem2px = function (e) {
            var t = parseFloat(e) * this.rem;
            return "string" == typeof e && e.match(/rem$/) && (t += "px"), t
          }, c.px2rem = function (e) {
            var t = parseFloat(e) / this.rem;
            return "string" == typeof e && e.match(/px$/) && (t += "rem"), t
          }
        }(window, window.lib || (window.lib = {}));
  • 相关阅读:
    使用 richtextbox 输出程序运行信息
    多线程 更新 winform 控件的值,以避免UI线程的卡顿
    多线程 以及 主程序退出时 子线程的销毁
    supersocket 通过配置文件启动服务 总是 初始化失败的 解决办法
    增删改存储过程 框架
    winform DataGridView 通用初始化
    SQLServer存储过程 实例,很多语法可以以后参考
    Winform中 DataGridView控件中的 CheckBox 的值读出来 始终 为 False ,已解决
    winform中 让 程序 自己重启
    字符数组什么时候要加‘’
  • 原文地址:https://www.cnblogs.com/bozhiyao/p/9252956.html
Copyright © 2011-2022 走看看