2019-04-16-移动端适配

document.documentElement.style.fontSize = window.innerWidth / 750 * 100 + 'px'; 

//获得屏幕大小

let htmlwidth = document.documentElement.clientWidth || document.body.clientWidth;  // 浏览器兼容

console.log("屏幕宽度:"+htmlwidth) //iphone5:320 iphone6:375

//获得html DOM元素

let htmlDom = document.getElementsByTagName('html')[0];

//给DOM元素设置样式

htmlDom.style.fontSize = htmlwidth/20 + 'px'; 

//以iphone5为基础 iphone5默认字体大小为16px 320/16=20 即1rem字体大小是屏幕宽度的1/20

---------------------

原文:https://blog.csdn.net/weixin_38840741/article/details/81364559

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容