移动端的js适配

(function() {

vardoc=document;

vardocEle=doc.documentElement;

function setRootFontSize(width) {

width=width||docEle.getBoundingClientRect().width;

docEle.style.fontSize=width/375*10+"px"

}

if(/Mobi|mljr/.test(navigator.userAgent)) { (function() {

vartimer;

setRootFontSize();

window.addEventListener("resize",

function() {

clearTimeout(timer);

timer=setTimeout(setRootFontSize,300)

},

false)

})()

}else{ (function() {

varpcWidth=750;

varstyle=doc.createElement("style");

style.innerHTML="body{width:"+pcWidth+"px!important;margin:0 auto!important}";

doc.getElementsByTagName("head")[0].appendChild(style);

setRootFontSize(pcWidth)

})()

}

})();

你可能感兴趣的:(移动端的js适配)