美文网首页
移动端的js适配

移动端的js适配

作者: 美滋滋213 | 来源:发表于2017-05-02 16:24 被阅读0次

(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适配

      本文链接:https://www.haomeiwen.com/subject/psactxtx.html