直接上代码:
window.onload = function () {
function setHtml() {
let cWidth =
document.body.clientWidth || document.documentElement.clientWidth;
let target = cWidth / 7.5;
document.documentElement.style.fontSize = target + "px";
}
/*
在375分辨率下,设置html根节点的font-size为100
375/20 = 414/target(在414分辨率下的html font-size值)
target=414/375*100
*/
setHtml();
window.onresize = setHtml;
}