移动端使用rem方法

1 在可以设置网页标题栏的页面写一个匹配手机的方法

<script>
       function resetWidth() {
            // 兼容ie浏览器 document.body.clientWidth
            var baseWidth = document.documentElement.clientWidth || document.body.clientWidth;
            console.log(baseWidth);
            // 默认的设置是375px(ip6)的根元素设为100px, 其他的手机都相对这个进行调整
            document.documentElement.style.fontSize = baseWidth / 375 * 100 + 'px'
        }
        resetWidth();
        window.addEventListener('resize', function () {
            resetWidth();
        })      
    </script>

 然后在html根目录设置默认大小

猜你喜欢

转载自www.cnblogs.com/gfweb/p/9765561.html