移动端计算单位 js

移动端计算单位 js

一、http://www.jq22.com/demo/gouwuche201708281153/

(function(doc, win) {
    var docEl = doc.documentElement
      , resizeEvt = 'orientationchange'in window ? 'orientationchange' : 'resize'
      , recalc = function() {
        var clientWidth = docEl.clientWidth;
        if (!clientWidth)
            return;
        docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
    };
    if (!doc.addEventListener)
        return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
}
)(document, window);

二、flexible.js

!function(t) {
    var e = 750
      , i = t.document
      , n = i.documentElement
      , o = "orientationchange"in t ? "orientationchange" : "resize"
      , a = function t() {
        var i = n.getBoundingClientRect().width;
        return n.style.fontSize = 5 * Math.max(Math.min(i / e * 20, 11.2), 8.55) + "px",
        t
    }();
    n.setAttribute("data-dpr", t.navigator.appVersion.match(/iphone/gi) ? t.devicePixelRatio : 1),
    /iP(hone|od|ad)/.test(t.navigator.userAgent) && (i.documentElement.classList.add("ios"),
    parseInt(t.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/)[1], 10) >= 8 && i.documentElement.classList.add("hairline")),
    i.addEventListener && (t.addEventListener(o, a, !1),
    i.addEventListener("DOMContentLoaded", a, !1))
}(window);

 

上一篇:网页head


下一篇:javascript – 处理事件时我可以依赖附加订单吗?