rem.ts
574 Bytes
/*
* @Description:
* @Author: huyue
* @Date: 2022-10-10 10:59:01
* @LastEditors: huyue
* @LastEditTime: 2022-10-29 14:54:02
*/
let baseSize = 37.5
function setRem() {
const scale = document.documentElement.clientWidth / 375
document.documentElement.style.fontSize = baseSize * Math.min(scale, 3) + 'px'
}
function throttle(func, wait) {
let timeout
return function () {
if (!timeout) {
timeout = setTimeout(function () {
func()
timeout = null
}, wait)
}
}
}
setRem()
window.onresize = throttle(() => {
setRem()
}, 1000)