20 lines
684 B
JavaScript
20 lines
684 B
JavaScript
// import postcssrc from "../postcssrc.config";
|
|
// const baseSize = 36;
|
|
|
|
function setRem() {
|
|
// 1920 默认大小16px; 1920px = 120rem ;每个元素px基础上/16 这里是16就是初始化根元素px大小
|
|
const screenWidth = 3158
|
|
const scale = screenWidth / 22.8
|
|
const htmlWidth = document.documentElement.clientWidth || document.body.clientWidth
|
|
// 得到html的Dom元素
|
|
const htmlDom = document.getElementsByTagName('html')[0]
|
|
console.log(htmlWidth / scale,'htmlWidth');
|
|
// 设置根元素字体大小
|
|
htmlDom.style.fontSize = htmlWidth / scale + 'px'
|
|
}
|
|
|
|
// 1579*684
|
|
setRem();
|
|
window.onresize = function () {
|
|
setRem();
|
|
} |