js自适应

//屏幕宽度自适应
(function (doc, win) {
  var docEl = doc.documentElement,
    resizeEvt =
      "orientationchange" in window ? "orientationchange" : "resize",
    recalc = function () {
      var clientWidth = docEl.clientWidth;
      if (!clientWidth) return;
      docEl.style.fontSize = clientWidth / (1920 / 16) + "px";//1920设计图的宽度,16字体为基准
    };
  if (!doc.addEventListener) return;
  win.addEventListener(resizeEvt, recalc, false);
  doc.addEventListener("DOMContentLoaded", recalc, false);
})(document, window);
posted @ 2019-08-21 11:34  米娅m  阅读(831)  评论(0编辑  收藏  举报