rem单位介绍:
rem
(font size of the root element)是相对长度单位。相对于根元素(即html元素)font-size
计算值的倍数
移动端主要根据iPhone5来参考适配,在谷歌浏览器中,1rem=16px;iphone5的宽度是320px,320/16=20
动态设置rem
//得到手机屏幕的宽度
let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
//当屏幕大于750px时
if(htmlWidth>750){htmlWidth=750}
//得到html的Dom元素
let htmlDom = document.getElementsByTagName('html')[0];
//设置根元素字体大小
htmlDom.style.fontSize= htmlWidth/20 + 'px';