UNPKG

create-vvt

Version:

一个基于 Vite + Vue3 + TypeScript/JavaScript 的项目模板脚手架

28 lines (21 loc) 643 B
class RemAdapter { private designWidth: number; private rootValue: number; constructor(designWidth: number = 1920, rootValue: number = 14) { this.designWidth = designWidth; this.rootValue = rootValue; this.init(); } private calculateRem(): void { const html: HTMLElement = document.documentElement; const width: number = html.clientWidth; html.style.fontSize = `${(width / this.designWidth) * this.rootValue}px`; } private init(): void { this.calculateRem(); window.addEventListener('resize', this.calculateRem.bind(this)); } } // 创建实例 new RemAdapter(); export default RemAdapter;