其他分享
首页 > 其他分享> > 动态设置rem

动态设置rem

作者:互联网

动态配置rem其实就是在窗口大小改变时重新设置rem的值

(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = "orientationchange" in window ? "orientationchange" : "resize",
        recalc = function() {
            if (docEl.clientWidth > 750) {
                docEl.style.fontSize = "100px";
                doc.getElementById("app").style.width = "750px";
            } else {
                var width = docEl.clientWidth / 7.5;
                docEl.style.fontSize = width + "px";
                doc.getElementById("app").style.width = "auto";
            }
        };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener("DOMContentLoaded", recalc, false);
})(document, window);

标签:style,doc,addEventListener,width,设置,rem,docEl,动态
来源: https://blog.csdn.net/weixin_53344545/article/details/118068282