手机端处理布局rem

方法一

  if (document.documentElement.clientWidth > 600) {//页面宽度大于600px让其宽度等于600px,字体大小等于60px,居中
    document.documentElement.style.width = "600px";
    document.documentElement.style.fontSize = "60px";
    document.documentElement.style.margin = "0 auto";
  } else {//否则让其根节点字体大小等于宽度/10px
    document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + "px";
  }

方法二

; (function (doc, win) {
var html = doc.documentElement, //html
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var hWidth = html.getBoundingClientRect().width;
if (!hWidth) return;
hWidth = Math.min(540, hWidth);
html.style.fontSize = (hWidth / 10) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
recalc();
})(document, window);
原文地址:https://www.cnblogs.com/hyx626/p/10122822.html