You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
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 > 1080) {
|
|
var whdef = 100 / 1920; // 表示1920的设计图,使用100PX的默认值
|
|
var wH = window.innerHeight; // 当前窗口的高度
|
|
var wW = window.innerWidth; // 当前窗口的宽度
|
|
var rem = wW * whdef; // 以默认比例值乘以当前窗口宽度,得到该宽度下的相应FONT-SIZE值
|
|
docEl.style.fontSize = rem + "px";
|
|
|
|
} else if(640 < clientWidth <= 1080) {
|
|
docEl.style.fontSize = '50px';
|
|
} else {
|
|
docEl.style.fontSize = 100 * (clientWidth / 640) + 'px';
|
|
}
|
|
|
|
};
|
|
|
|
if(!doc.addEventListener) return;
|
|
recalc();
|
|
win.addEventListener(resizeEvt, recalc, false);
|
|
doc.addEventListener('DOMContentLoaded', recalc, false);
|
|
/*DOMContentLoaded文档加载完成不包含图片资源 onload包含图片资源*/
|
|
})(document, window);
|
|
|
|
/*
|
|
|
|
var iWidth=document.documentElement.clientWidth //getBoundingClientRect().width;
|
|
iWidth=iWidth>640?640:iWidth;
|
|
document.getElementsByTagName("html")[0].style.fontSize=iWidth/6.4+"px";*/ |