移动端rem布局适配

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

你可能感兴趣的:(移动端rem布局适配)