1. 程式人生 > >動態設定rem

動態設定rem

function () {
        function e() {
            r.innerText = "html{font-size:" + (a.style.fontSize = a.getBoundingClientRect().width / o * d + "px") + " !important;}"
        }
        var t = navigator.userAgent,
            n = (t.match(/(iPhone|iPad|iPod)/), t.match(/Android/i), window),
            i = document,
            a = i.documentElement,
            o = (n.devicePixelRatio || 1, 375),
            d = 50,
            r = (i.head.querySelector('[name="viewport"]'), i.createElement("style"));
        r.innerText = "html{font-size:50px !important}", i.head.appendChild(r), e(), n.addEventListener("resize", e, !1), a.className += t.match(/ucbrowser/i) ? " app-uc " : ""
    }();