13 lines
541 B
JavaScript
13 lines
541 B
JavaScript
(function(doc, win) {
|
||
var docEl = doc.documentElement,
|
||
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
|
||
recalc = function() {
|
||
var clientWidth = docEl.clientWidth;
|
||
if (!clientWidth) return;
|
||
if(clientWidth>500) clientWidth=500
|
||
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px'; //在320px的屏幕上,1rem=20px
|
||
};
|
||
if (!doc.addEventListener) return;
|
||
win.addEventListener(resizeEvt, recalc, false);
|
||
doc.addEventListener('DOMContentLoaded', recalc, false);
|
||
})(document, window); |