zoukankan      html  css  js  c++  java
  • 百度 前端 rem 适配 和 阿里 前端 rem 适配

    阿里 

    <script>
      var html = document.documentElement;
      window.rem = html.getBoundingClientRect().width / 37.5;
      html.style.fontSize = window.rem + 'px';
      </script>

    阿里2 

    <script>
      (function(doc, win) {
      var docEle = doc.documentElement,
      evt = "onorientationchange" in window ? "orientationchange" : "resize",
      fn = function() {
      var width = docEle.clientWidth;
      width && (docEle.style.fontSize = 10 * (width / 375) + "px")
      }
      win.addEventListener(evt, fn, false);
      doc.addEventListener("DOMContentLoaded", fn, false)
       
      }(document, window))
      </script>

    百度

     (function () {
    var newFontSize = window.getComputedStyle(document.documentElement)['font-size'];
    var fontSizeScale = 16 / parseFloat(newFontSize.replace('px','')) ;
    //获取屏幕大小
    var html = document.documentElement;
    document.addEventListener('DOMContentLoaded', function () {
    resetRem();
    resetScreen();
    });
    window.addEventListener('load', function () {
    setTimeout(resetRem, 300);
    resetScreen();
    });
    window.addEventListener('resize', function () {
    setTimeout(resetRem, 300);
    resetScreen();
    });
    function resetRem() {
    html.style.fontSize = html.clientWidth / 20 * fontSizeScale + 'px';
    console.log(html.clientWidth);
    console.log(html.style.fontSize);
    }
    function resetScreen() {
    window.scrollTo(0,0);
    // var height = html.clientHeight || window.innerHeight;
    // var width = html.clientWidth || window.innerWidth;
    // document.querySelector('body').style.height = height + 'px';
    // document.querySelector('body').style.width = width + 'px';
    // document.querySelector('body').style.margin = 0;
    // document.querySelector('body').style.padding = 0;
    }
    resetRem();
    })();
  • 相关阅读:
    手动安装vue-devtools
    redis随记
    JS时间格式化
    360自动抢票还不够,几行js代码设置无人值守
    HttpWebRequest请求返回非200的时候 HttpWebResponse怎么接受返回错误提示
    android发编译
    asprise-ocr-api-sample 高价收破解版64 32位
    (16)集合操作
    (15)字典操作
    (14)字符串
  • 原文地址:https://www.cnblogs.com/itliulei/p/9223386.html
Copyright © 2011-2022 走看看