一、适用于PC端
(function (window, document) {
let docEl = document.documentElement
let _width = docEl.clientWidth
function fn1() {
if (!_width) {
return
}
if (_width > 750) {
docEl.style.fontSize = '100px'
} else {
docEl.style.fontSize = (_width / 7.5) + 'px'
}
}
window.addEventListener('resize', fn1)
document.addEventListener('DOMConetntLoaded', fn1)
})(window, document)
二、适用于移动端
document.addEventListener('DOMContentLoaded', () => {
const html = document.querySelector("html")
let fontSize = window.innerWidth / 10
fontSize = fontSize > 50 ? 50 : fontSize
html.style.fontSize = fontSize + "px"
})