px转rem 直接100 复制粘贴就行

<script>
    //px转换rem js控制
    (function (win) {
        var doc = win.document;
        var docEl = doc.documentElement;
        var tid;


        function refreshRem() {
            var width = docEl.getBoundingClientRect().width;//获取宽度
            if (width > 640) { // 最大宽度
                width = 640;
            }
            var rem = width / 6.4;
            docEl.style.fontSize = rem + 'px';
        }


        win.addEventListener('resize', function () {
            clearTimeout(tid);
            tid = setTimeout(refreshRem, 300);
        }, false);
        win.addEventListener('pageshow', function (e) {
            if (e.persisted) {
                clearTimeout(tid);
                tid = setTimeout(refreshRem, 300);
            }
        }, false);


        refreshRem();
    })(window);
</script>

猜你喜欢

转载自blog.csdn.net/supercaojh/article/details/79143303