|
@@ -0,0 +1,20 @@
|
|
1
|
+const baseSize = 32;
|
|
2
|
+// 设置 rem 函数
|
|
3
|
+function setRem() {
|
|
4
|
+ const scale = document.documentElement.clientWidth / 750;
|
|
5
|
+ document.documentElement.style.fontSize =
|
|
6
|
+ baseSize * Math.min(scale, 2) + "px";
|
|
7
|
+ // // 320 默认大小16px; 320px = 20rem ;每个元素px基础上/16
|
|
8
|
+ // let htmlWidth =
|
|
9
|
+ // document.documentElement.clientWidth || document.body.clientWidth;
|
|
10
|
+ // //得到html的Dom元素
|
|
11
|
+ // let htmlDom = document.getElementsByTagName("html")[0];
|
|
12
|
+ // //设置根元素字体大小
|
|
13
|
+ // htmlDom.style.fontSize = htmlWidth / 23.4375 + "px";
|
|
14
|
+}
|
|
15
|
+// 初始化
|
|
16
|
+setRem();
|
|
17
|
+// 改变窗口大小时重新设置 rem
|
|
18
|
+window.onresize = function() {
|
|
19
|
+ setRem();
|
|
20
|
+};
|