function resize () { const baseFontSize = 16 const windowWidth = document.documentElement.clientWidth; const newVal = Math.round((windowWidth / 1920) * baseFontSize) document.documentElement.style.fontSize = `${newVal}px`; } resize() //先调用一次,适配初次加载屏幕大小 window.addEventListener('resize', resize); //挂载窗口大小事件