wszhyWx/src/rem/rem.js
2023-11-16 10:11:37 +08:00

21 lines
559 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// rem等比适配配置文件
// 基准大小
const baseSize = 100;
// 设置 rem 函数
function setRem() {
// 当前页面宽度相对于 1920宽的缩放比例可根据自己需要修改。
const scale = window.innerWidth / 1920;
// 设置页面根节点字体大小“Math.min(scale, 2)” 指最高放大比例为2可根据实际业务需求调整
document.documentElement.style.fontSize = baseSize * scale + "px";
}
// 初始化
setRem();
// 改变窗口大小时重新设置 rem
window.onresize = function () {
setRem();
};