(function(win) {
      var doc = win.document;
      var docEl = doc.documentElement;
      var tid;
      function refreshRem() {
          var width = docEl.getBoundingClientRect().width;
          if (width > 640) { // 最大宽度
              width = 640;
          }
          var rem = width / 10; // 将屏幕宽度分成10份, 1份为1rem
          docEl.style.fontSize = rem + 'px';
      }
      win.addEventListener('resize', function() {
          clearTimeout(tid);
          tid = setTimeout(refreshRem, 300);
      }, false);
      win.addEventListener('pageshow', function(e) {
          if (e.persisted) {
              clearTimeout(tid);
              tid = setTimeout(refreshRem, 300);
          }
      }, false);
      refreshRem();
      console.log(docEl.style.fontSize)
})(window);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-04-08
  • 2022-12-23
  • 2021-12-26
  • 2021-11-30
相关资源
相似解决方案