移动端rem.js

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)
})

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0