rem根据屏幕大小适配字体大小

(function(window, document) {
    function rootSize() {
        var screenWidth = document.documentElement.clientWidth || window.innerWidth;
        //        console.log(screenWidth);
        var rootSize = screenWidth > 750 ? 100 :
            screenWidth < 320 ? 320 / 750 * 100 : screenWidth / 750 * 100;
        document.documentElement.style.fontSize = rootSize + 'px';
    }
    //        window.addEventListener('DOMContentLoaded',rootSize);
    window.onload = function() {
        rootSize();
    };
    window.onresize = function() {
        rootSize();
    }
})(window, document);
posted @ 2018-02-26 10:28  胡珂儿  阅读(379)  评论(0编辑  收藏  举报