美文网首页
保留一个rem的处理js

保留一个rem的处理js

作者: Littlehey | 来源:发表于2019-01-08 18:58 被阅读0次
    !function(e, t) {
        function n() {
            var t = o.getBoundingClientRect().width;
            if (t < 320) {
                t = 320
            }
            ;n = t / 7.5;
            o.style.fontSize = n + "px",
            d.rem = e.rem = n
        }
        var i, r = e.document, o = r.documentElement, a = 0, d = t.flexible || (t.flexible = {}), s = e.navigator.appVersion.match(/iphone/gi), m = e.navigator.appVersion.match(/UCBrowser/gi), p = e.devicePixelRatio;
        a = s ? p >= 3 && (!a || a >= 3) ? 3 : p >= 2 && (!a || a >= 2) ? 2 : 1 : 1,
        o.setAttribute("data-dpr", a),
        "complete" === r.readyState ? r.body.style.fontSize = "50px" : r.addEventListener("DOMContentLoaded", function() {
            r.body.style.fontSize = "50px"
        }, !1);
        var c = "onorientationchange"in window ? "orientationchange" : "resize";
        if (e.addEventListener(c, function() {
            clearTimeout(i),
            i = setTimeout(n, 300)
        }, !1),
        e.addEventListener("pageshow", function(e) {
            e.persisted && (clearTimeout(i),
            i = setTimeout(n, 300))
        }, !1),
        n(),
        d.dpr = e.dpr = a,
        d.refreshRem = n,
        d.rem2px = function(e) {
            var t = parseFloat(e) * this.rem;
            return "string" == typeof e && e.match(/rem$/) && (t += "px"),
            t
        }
        ,
        d.px2rem = function(e) {
            var t = parseFloat(e) / this.rem;
            return "string" == typeof e && e.match(/px$/) && (t += "rem"),
            t
        }
        ,
        s && !m) {
            var l = "notHairlines"
              , u = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/)
              , f = parseInt(u[1], 10);
            f >= 8 && (l = "hairlines"),
            document.documentElement.classList.add(l)
        }
    }(window, window.lib || (window.lib = {}));
    
    

    相关文章

      网友评论

          本文标题:保留一个rem的处理js

          本文链接:https://www.haomeiwen.com/subject/zpbbrqtx.html