//100px = 1rem
window.onload = function () {
sizeWidth()
}
window.onresize = function () {
sizeWidth()
}
function sizeWidth () {
// 获取当前屏幕的宽度
var screenWidth = document.querySelector('html').offsetWidth
// 基础值
var baseSz = 100
// 设计稿的宽度
var pageWidth = 750
// 套用公式
if (screenWidth > 750) screenWidth = 750
var fZ = baseSz * screenWidth / pageWidth
// 直接给元素赋值
document.querySelector('html').style.fontSize = fZ + 'px'
}
rem自适应布局
最新推荐文章于 2023-07-19 14:51:02 发布