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();
    })();
  • 相关阅读:
    Oracle序列更新
    ssh服务器终端乱码
    iTerm2常用的快捷键
    原来 Set 集合也可以排序
    Java 单例
    java后台技术
    网易考拉规则引擎平台架构设计与实践
    HBase最佳实践(好文推荐)
    如何通俗的解释云
    写的不错的一篇云数据库的文章
  • 原文地址:https://www.cnblogs.com/itliulei/p/9223386.html
Copyright © 2011-2022 走看看