<script>
(function remSetting (win) {
const doc = win.document
const docEl = doc.documentElement
let timer
const refreshRem = function() {
let width = docEl.getBoundingClientRect().width
if (width > 750) {
width = 750
} else if (width < 320) {
width = 320
}
const rem = width / 7.5 // width/750/100 根据实际调整
docEl.style.fontSize = rem + 'px'
}
win.addEventListener('resize', () => {
clearTimeout(timer)
timer = setTimeout(refreshRem, 300)
}, false)
win.addEventListener('pageshow', (e) => {
if (e.persisted) {
clearTimeout(timer)
timer = setTimeout(refreshRem, 300)
}
}, false)
if (doc.readyState === 'complete') {
doc.body.style.fontSize = '12px'
} else {
doc.addEventListener('DOMContentLoaded', () => {
doc.body.style.fontSize = '12px'
}, false)
}
refreshRem()
}(window))
</script>
rem.js
最新推荐文章于 2024-11-12 11:19:19 发布