forked from amfe/lib-flexible
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflexible.js
More file actions
37 lines (33 loc) · 1.16 KB
/
Copy pathflexible.js
File metadata and controls
37 lines (33 loc) · 1.16 KB
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
;(function(win) {
var h;
var dpr = win.navigator.appVersion.match(/iphone/gi)?win.devicePixelRatio:1;
var scale = 1 / dpr;
var docEl = document.documentElement;
var metaEl = document.createElement('meta');
function setUnitA(){
win.rem = docEl.getBoundingClientRect().width / 16;
docEl.style.fontSize = win.rem + 'px';
}
win.dpr = dpr;
win.addEventListener('resize', function() {
clearTimeout(h);
h = setTimeout(setUnitA, 300);
}, false);
win.addEventListener('pageshow', function(e) {
if (e.persisted) {
clearTimeout(h);
h = setTimeout(setUnitA, 300);
}
}, false);
docEl.setAttribute('data-dpr', dpr);
metaEl.setAttribute('name', 'viewport');
metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');
if (docEl.firstElementChild) {
docEl.firstElementChild.appendChild(metaEl);
} else {
var wrap = document.createElement('div');
wrap.appendChild(metaEl);
document.write(wrap.innerHTML);
}
setUnitA();
})(window);