const deviceWidth = 1920;
const deviceHeight = 1080;
const rem = 100;
const clientWidth = document.documentElement.clientWidth;
const clientHeight = document.documentElement.clientHeight;
const base = (clientWidth/clientHeight<=(deviceWidth/deviceHeight))?clientWidth:clientHeight * (deviceWidth/deviceHeight)
document.documentElement.style.fontSize = base * rem / deviceWidth +'px';
window.onresize = function () {
document.documentElement.style.fontSize = base * rem / deviceWidth +'px';
}
配置rem根元素
最新推荐文章于 2023-01-30 11:43:36 发布