zoukankan      html  css  js  c++  java
  • 移动端响应式js代码

    最大宽度为640 1rem = 32px:
    (function() {
    var b = document.documentElement,
    a = function() {
    var a = b.getBoundingClientRect().width;
    b.style.fontSize = .0625 * (640 <= a ? 640 : a) + "px"
    },
    c = null;
    window.addEventListener("resize",
    function() {
    clearTimeout(c);
    c = setTimeout(a, 300)
    });
    a()
    })();
    最大宽度为640 1rem = 32px:
    (function() {
    var b = document.documentElement,
    a = function() {
    var a = b.getBoundingClientRect().width;
    b.style.fontSize = .005 * (640 <= a ? 640 : a) + "px"
    },
    c = null;
    window.addEventListener("resize",
    function() {
    clearTimeout(c);
    c = setTimeout(a, 300)
    });
    a()
    })();

    不限制最大宽度:

    (function (root) {
    var docEl = document.documentElement,
    timer = null,
    width, last;

    function changeRem () {
    width = docEl.getBoundingClientRect().width;
    if (last === width) { return; }
    last = width;
    root.rem = width / 20;
    if (/ZTE U930_TD/.test(navigator.userAgent)) {
    root.rem = root.rem * 1.13;
    }
    docEl.style.fontSize = root.rem + 'px';
    }

    changeRem();

    root.addEventListener('resize', function () {
    clearTimeout(timer);
    timer = setTimeout(changeRem, 300);
    });

    root.addEventListener('orientationchange', function () {
    clearTimeout(timer);
    timer = setTimeout(changeRem, 300);
    });
    })(window, undefined);

  • 相关阅读:
    WDK中出现的特殊代码
    敏捷是怎样炼成的
    推荐一个非常好玩的falsh游戏
    软件安全技术
    J2EE的昨天,今天,明天
    Java打印程序设计
    关于父亲
    xml发展历史和用途
    CRM与ERP整合的六个切入点
    SEO(搜索引擎最佳化)简介
  • 原文地址:https://www.cnblogs.com/anyaran/p/4651542.html
Copyright © 2011-2022 走看看