js设置rem代码

<script type="text/javascript">
    (function(doc, win) {
        var docEl = doc.documentElement,
        isIOS = navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
        dpr = isIOS ? Math.min(win.devicePixelRatio, 3) : 1,
        dpr = window.top === window.self ? dpr : 1,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
        docEl.dataset.dpr = dpr;
        var recalc = function() {
        var width = docEl.clientWidth;
        if (width / dpr > 750) {
        width = 750 * dpr;
        }
        docEl.dataset.width = width
        docEl.dataset.percent = 100 * (width / 750);
        docEl.style.fontSize = 100 * (width / 750) + 'px';
        };
        recalc()
        if (!doc.addEventListener) return;
        win.addEventListener(resizeEvt, recalc, false);
        })(document, window);
    </script>

欢迎分享本文,转载请保留出处:前端ABC » js设置rem代码

赞 (2)
分享到:更多 ()

发表评论 0