rem的使用

第一种直接在html里插入script

<script>
          document.documentElement.style.fontSize=innerWidth/3.75+"px";
          window.onresize=function(){
              document.documentElement.style.fontSize=innerWidth/3.75+"px";
          }
 </script>

第二种

var computedFz = (function(){
  var designWidth = 375, rem2px = 100;
  function computedFz(){
    var fz = Math.floor(window.innerWidth / designWidth * rem2px);
    document.documentElement.style.fontSize = (fz > 100 ? 100 : fz) + 'px'
  }
    return computedFz;
})()
computedFz();
window.onresize = function(){
  setTimeout(computedFz,500);
}
原文地址:https://www.cnblogs.com/ldlx-mars/p/7772750.html