zoukankan      html  css  js  c++  java
  • rem 转 px

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

      第二种方法

    (function() {
        var newRem = function() {
            var html = document.documentElement;
            html.style.fontSize = html.getBoundingClientRect().width / 16 + 'px';
        };
        window.addEventListener('resize', newRem, false);
        newRem();
    })();
    

      

  • 相关阅读:
    Adobe Flash Player 设置鼠标点不到允许或者拒绝!
    bzoj2096
    bzoj2789
    LA3353
    poj2594
    bzoj2427
    bzoj1076
    bzoj2818
    bzoj3668
    bzoj2006
  • 原文地址:https://www.cnblogs.com/liujun1128/p/10049836.html
Copyright © 2011-2022 走看看