1 |
|
2 |
|
3 |
|
4 |
|
5 | import { throttle } from './StringUtils'
|
6 | import appConfig from '@cwd/app.config'
|
7 |
|
8 | const win = global
|
9 | const doc = win.document
|
10 | const baseWidth = appConfig.designSize || 750
|
11 | const optimalSize = appConfig.optimalSize || 414
|
12 | const documentHTML = doc.documentElement
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function setRootFont() {
|
18 | const docWidth = documentHTML.getBoundingClientRect().width
|
19 | const scale = (docWidth > 720 ? optimalSize : docWidth) / baseWidth
|
20 | documentHTML.style.fontSize = `${scale * 100}px`
|
21 | documentHTML.setAttribute('data-dpr', global.devicePixelRatio === 3 ? 3 : 2)
|
22 | }
|
23 |
|
24 | setRootFont()
|
25 | win.addEventListener('resize', throttle(setRootFont, 90, 100), false)
|
26 |
|