function remRefresh() {
let clientWidth = document.documentElement.clientWidth;
// 将屏幕分成10等份
let rem = clientWidth / 10;
document.documentElement.style.fontSize = rem + 'px'
document.body.style.fontSize = '12px'
}
window.addEventListener('pageshow', () => {
remRefresh()
})
// 函数防抖
let timeoutId;
window.addEventListener('resize', () => {
timeoutId && clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
remRefresh()
}, 300)
})
移动端rem.js
点赞
收藏