1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| var rem = {
baseRem: 40,
// 基准字号,按照iphone6应该为20,此处扩大2倍,便于计算
baseWidth: 750,
// 基准尺寸宽,此处是按照ihpone6的尺寸
rootEle: document.getElementsByTagName("html")[0],
initHandle: function () {
this.setRemHandle();
this.resizeHandle();
},
setRemHandle: function () {
var clientWidth =
document.documentElement.clientWidth || document.body.clientWidth;
this.rootEle.style.fontSize =
(clientWidth * this.baseRem) / this.baseWidth + "px";
},
resizeHandle: function () {
var that = this;
window.addEventListener("resize", function () {
setTimeout(function () {
that.setRemHandle();
}, 300);
});
},
};
rem.initHandle();
|