zoukankan      html  css  js  c++  java
  • 学习web前端技术的笔记,仅供自己查阅备忘,移动对font-size的控制(并非原创)

    假设根字体font-size的值是40px, 640/40=16,16就是px换算rem的值

    function initHtmlFontSize(){

      //获取可可视屏幕的宽度

      var _width=document.body.clientWidth;

      //判断

      _width= _width > 640 ? 640:_width;

      //当前的font-size的值

      var _fs=_width/16;

         //赋给html节点

      document.getElementsByTagName('html')[0].style.fontSize=_fs + 'px';

    }

    initHtmlFontSize()

    经过@天桥残局的优化顿时有深度有高度局长daio,上代码:

    !(function(doc, win) {
    var docEle = doc.documentElement,
    evt = "onorientationchange" in window ? "orientationchange" : "resize",
    fn = function() {
    var width = docEle.clientWidth;
    width && (docEle.style.fontSize = doc.documentElement.clientWidth/16 + "px");
    };

    win.addEventListener(evt, fn, false);
    doc.addEventListener("DOMContentLoaded", fn, false);

    }(document, window));
  • 相关阅读:
    LeetCode --- Climbing Stairs
    LeetCode --- Best Time to Buy and Sell Stock II
    LeedCode --- Best Time to Buy and Sell Stock
    git命令总结
    LeetCode --- Jump Game II
    Hdu 4497
    数据库lib7第4题创建存储过程
    Hdu 4496
    Hdu 4493
    快速排序
  • 原文地址:https://www.cnblogs.com/opcec/p/5430186.html
Copyright © 2011-2022 走看看