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元素設(shè)置樣式
htmlDom.style.fontSize = htmlwidth/20 + 'px';?
//以iphone5為基礎(chǔ) iphone5默認(rèn)字體大小為16px 320/16=20 即1rem字體大小是屏幕寬度的1/20
---------------------
原文:https://blog.csdn.net/weixin_38840741/article/details/81364559