pc网页手机自适应

adaptive(document, window);//初始加载自适应
function adaptive(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth;
if(clientWidth<900){
clientWidth=900
}
if(!clientWidth) return;
if(clientWidth >= 1920) {
docEl.style.fontSize = '70px';//这个是根据我自己项目调的
} else {
docEl.style.fontSize = 70 * (clientWidth / 1920) + 'px';
}
};
if(!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
}
//随浏览器大小自适应
window.onresize = function() {
adaptive(document, window);
}

posted @ 2020-12-03 21:45  ˉ八月  阅读(110)  评论(0编辑  收藏  举报