!function(window, document) {
function setSize() {
// 设备宽度
let deviceWidth = window.screen.width;
// 设计稿宽度
const baseValue = 750;
// html的字体大小 = (设备宽度 / 设计稿宽度) * 100
document.documentElement.style.fontSize = (deviceWidth / baseValue) * 100 + 'px';
}
// DOM树加载完执行
window.addEventListener("DOMContentLoaded", function() {
setSize();
})
// 屏幕变化执行
window.addEventListener("resize", function() {
setSize();
})
setSize();
}(window, document)html 的 size = (设备的宽度 / 设计稿的尺寸) * 100%
比如设计稿是750px,有个按钮是 590px 换算之后就是 5.9rem
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。