(function(doc, win) { this.width = 750 // 设置默认最大宽度 this.fontSize = 34 // 默认字体大小 this.widthProportion = () => { let p = (document.body && document.body.clientWidth || document.getElementsByTagName("html")[0].offsetWidth) / this.width let s = document.body && document.body.clientWidth console.log(s, p) return s > 414 ? 0.5 : (p > 1 ? 1 : p < 0.5 ? 0.5 : p) } console.log('widthProportion is : ' , this.widthProportion()) this.changePage = () => { document.getElementsByTagName("html")[0].setAttribute('style', `font-size: ${this.widthProportion() * this.fontSize}px !important`) } this.changePage() window.addEventListener('resize', () => { this.changePage() }, false) })(document, window)