-
Notifications
You must be signed in to change notification settings - Fork 7
/
adaptive.js
39 lines (34 loc) · 923 Bytes
/
adaptive.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
/**
* create by iLong
*/
;(function () {
var doc = window.document,
docEl = doc.documentElement,
tid;
function refreshRem() {
var width = docEl.getBoundingClientRect().width;
if(width > 540){
width = 540;
}
var rem = width / 10;
docEl.style.fontSize = rem+'px';
}
window.addEventListener('resize',function () {
clearTimeout(tid);
tid = setTimeout(refreshRem,100);
},false);
window.addEventListener('pageshow',function (e) {
if(e.persisted){
clearTimeout(tid);
tid = setTimeout(refreshRem,100);
}
},false);
if (doc.readyState === 'complete') {
doc.body.style.fontSize = 12 + 'px';
} else {
doc.addEventListener('DOMContentLoaded', function() {
doc.body.style.fontSize = 12 + 'px';
}, false);
}
refreshRem();
})();