JS px转rem

132 阅读1分钟

在多数的移动端项目中,都需要做到页面自适应。


<script>
    !function () {
         var pageWid = 750; 
         function a() { 
              document.documentElement.style.fontSize = document.documentElement.clientWidth / pageWid * 10 / 16 * 1000 + "%"
             }
             var b = null; 
             window.addEventListener("resize", function () { 
              clearTimeout(b);
              b = setTimeout(a, 100) 
             }, !1);
         a() 
    }(window);
</script>