移动端适配js

1       //得到手机屏幕的宽度
2       let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
3       //得到html的Dom元素
4       let htmlDom = document.getElementsByTagName(html)[0];
5       //设置根元素字体大小 为什么除以20,因为我们是以iphone5为标准,它的width为320,font-size为16
6       htmlDom.style.fontSize= htmlWidth/20 + px;

 

这样就可以和rem配合使用,实现移动端的适配了