-
Notifications
You must be signed in to change notification settings - Fork 0
/
rem.js
41 lines (28 loc) · 892 Bytes
/
rem.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// JavaScript Document
!(function(win, doc){
function setFontSize() {
var docEl = doc.documentElement;
var winWidth = docEl.clientWidth;
if(winWidth<=640){
doc.documentElement.style.fontSize = (winWidth / 640) * 100 + 'px' ;
//document.body.style.fontSize=0.24+'rem';
}
else{
docEl.style.fontSize=100+"px";
document.body.style.fontSize=20+'px';
}
}
var evt = 'onorientationchange' in win ? 'orientationchange' : 'resize';
var timer = null;
win.addEventListener(evt, function () {
clearTimeout(timer);
timer = setTimeout(setFontSize, 300);
}, false);
win.addEventListener("pageshow", function(e) {
if (e.persisted) {
clearTimeout(timer);
timer = setTimeout(setFontSize, 300);
}
}, false);
setFontSize();
}(window, document));