手机端自适应调整字号

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

你可能感兴趣的:(手机端自适应调整字号)