适配

!(function (doc, win) {
  // 拿到html标签的dom元素对象
  var docEle = doc.documentElement,
    evt = "onorientationchange" in window ? "orientationchange" : "resize",
    fn = function () {
      // 拿到当前屏幕的尺寸。
      var width = docEle.clientWidth;
      width = width < 320 ? 320 : width;
      width = width > 750 ? 750 : width;
      width && (docEle.style.fontSize = 100 * (width / 750) + "px");

      setTimeout(function() {
        var width = docEle.clientWidth;
        width = width < 320 ? 320 : width;
        width = width > 750 ? 750 : width;
        width && (docEle.style.fontSize = 100 * (width / 750) + "px");
      }, 333);
    };

  win.addEventListener(evt, fn, false);
  doc.addEventListener("DOMContentLoaded", fn, false);

}(document, window));
posted @ 2021-12-21 19:19  Action_swt  阅读(259)  评论(0编辑  收藏  举报