移动端自适应js

时间:2022-03-02 05:34:43

<script>
        //移动端自适应
        (function (doc, win) {
            var docEl = doc.documentElement,
                    resizeEvt = ‘orientationchange‘ in window ? ‘orientationchange‘ : ‘resize‘,
                    recalc = function () {
                        var clientWidth = docEl.clientWidth;
                        if (!clientWidth) return;
                        docEl.style.fontSize = 100 * (clientWidth / 750)   ‘px‘;
                    };
            if (!doc.addEventListener) return;
            win.addEventListener(resizeEvt, recalc, false);
            doc.addEventListener(‘DOMContentLoaded‘, recalc, false);
        })(document, window);
</script>
style
html,body{width:100%}
.container{width:7.5rem}/*即750px*/