// 设置 rem 函数 export function setRem() { const doc = document const h = Math.max(doc.documentElement.clientHeight, window.innerHeight || 0) const w = Math.max(doc.documentElement.clientWidth, window.innerWidth || 0) let width = w width = width > 750 ? 750 : width const fz = ~~((width * 100000) / 100) / 10000 doc.getElementsByTagName('html')[0].style.cssText = 'font-size: ' + fz + 'px' const realfz = ~~( +window .getComputedStyle(doc.getElementsByTagName('html')[0]) .fontSize.replace('px', '') * 10000 ) / 10000 if (fz !== realfz) { doc.getElementsByTagName('html')[0].style.cssText = 'font-size: ' + fz * (fz / realfz) + 'px' } } // 初始化 setRem() // 改变窗口大小时重新设置 rem window.onresize = function() { setRem() }