zoukankan      html  css  js  c++  java
  • 今天分享下移动端rem 适配

    采用rem布局时,把以下代码粘到js文件内
    function font(w) {
    var w = w || 640,
    docEl = document.documentElement,
    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function () {
    var clientWidth = docEl.clientWidth;
    if (!clientWidth) return;
    docEl.style.fontSize = 100 * (clientWidth / w) + 'px';
    };
    if (!document.addEventListener) return;
    window.addEventListener(resizeEvt, recalc, false);
    document.addEventListener('DOMContentLoaded', recalc, false);
    }

    font();

    (function (doc, win) {
    var docEl = doc.documentElement,
    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function () {
    var clientWidth = docEl.clientWidth;
    if (!clientWidth) return;
    docEl.style.fontSize = 100 * (clientWidth / 640) + 'px';
    };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
    })(document, window);

  • 相关阅读:
    The hardest problem ever
    1146 Topological Order
    1147 Heaps
    Weekly Contest 184
    1148 Werewolf
    1149 Dangerous Goods Packaging
    1150 Travelling Salesman Problem
    1151 LCA in a Binary Tree (30point(s))
    1152 Google Recruitment
    美团2020春招笔试
  • 原文地址:https://www.cnblogs.com/wplcc/p/6667472.html
Copyright © 2011-2022 走看看