移动端rem布局

(function (documents, windows) {
    var domElement = documents.documentElement,
      resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
      setRem = function () {
        var clientWidth = domElement.clientWidth;
        if (!clientWidth) return;
        if (clientWidth >= 750) {
          domElement.style.fontSize = '100px';
        } else {
          domElement.style.fontSize = 100 * (clientWidth / 750) + 'px';
        }
      };

    if (!documents.addEventListener) return;
    windows.addEventListener(resizeEvt, setRem, false);
    documents.addEventListener('DOMContentLoaded', setRem, false);
    setRem();
  })(document, window);

上面750为设计稿像素

你可能感兴趣的:(移动端rem布局)