html5字体自适应

  <script>
        (function (doc, win) {
            var docEle = doc.documentElement,
                resizeEvent = 'orientationchange' in window ? 'orientationchange' : 'resize';
            var recalCulate = function () {
                var width = docEle.clientWidth;
                docEle.style.fontSize = 100 * (width / 750) + 'px'; // 设计稿 750px  
            };
            recalCulate();

            if (!doc.addEventListener) return;
            win.addEventListener(resizeEvent, recalCulate, false);
        })(document, window);

    </script>

eg.     font-szie: 18px;  写成  font-size: 0.36rem; 

posted on 2021-03-26 17:37  小虾米吖~  阅读(131)  评论(0编辑  收藏  举报