移动端rem布局

 1 //该模块实现移动端rem布局
 2 function remSize() {
 3   let deviceWidth = document.documentElement.clientWidth || window.innerWidth //获取屏幕宽度
 4   if (deviceWidth >= 750) {
 5     deviceWidth = 750  //pc端屏幕宽度如果大于750也直接设置成750
 6   }
 7   if (deviceWidth <= 320) {
 8     deviceWidth = 320  //移动端屏幕宽度不能小于320
 9   }
10   
11   //设计稿是750px
12   //设置一半的宽度。就是375px
13   //1rem = 100px的设计稿宽度
14   //一半宽度rem就是 3.75rem
15   document.documentElement.style.fontSize = (deviceWidth / 7.5) + 'px'
16   
17   //设置默认字体大小
18   document.body.style.fontSize = 0.3 + 'rem'
19 }
20   
21 remSize()
22   
23 window.onresize = function () {
24   remSize()
25 }
原文地址:https://www.cnblogs.com/qihang0/p/14136981.html