<script>
// 节流
var flag = true;
function setRem() {
if (flag) {
flag = false;
var ui_w = 375;
// 获取屏幕的宽度
var clientWidth = document.documentElement.clientWidth || document.body.clientWidth;
console.log(ui_w, clientWidth);
// 通过js动态改变html根节点字体大小
var html_ = document.getElementsByTagName('html')[0];
html_.style.fontSize = (clientWidth / ui_w) * 10 + 'px';
setTimeout(function () {
flag = true;
}, 700)
}
}
// window.onresize 浏览器被重置大小执行事件
window.onresize = setRem;
// 当页面加载完成调用
window.onload = setRem;
</script>
通过js动态设置字体大小
于 2022-11-07 14:49:46 首次发布