hlyin

/**可伸缩布局方案
 * rem计算方式:设计图尺寸px / 100 = 实际rem  例: 100px = 1rem
 */
!function (window) {

    /* 设计图文档宽度 */
    var docWidth = 1920;

    var doc = window.document,
        docEl = doc.documentElement,
        resizeEvt = \'orientationchange\' in window ? \'orientationchange\' : \'resize\';

    var recalc = (function refreshRem () {
        var clientWidth = docEl.getBoundingClientRect().width;

        docEl.style.fontSize = Math.max(Math.min(20 * (clientWidth / docWidth), 30), 8.55) * 5 + \'px\';

        return refreshRem;
    })();

    /* 添加倍屏标识,安卓倍屏为1 */
    docEl.setAttribute(\'data-dpr\', window.navigator.appVersion.match(/iphone/gi) ? window.devicePixelRatio : 1);

    if (/iP(hone|od|ad)/.test(window.navigator.userAgent)) {
        /* 添加IOS标识 */
        doc.documentElement.classList.add(\'ios\');
        /* IOS8以上给html添加hairline样式,以便特殊处理 */
        if (parseInt(window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/)[1], 10) >= 8)
            doc.documentElement.classList.add(\'hairline\');
    }

    if (!doc.addEventListener) return;
    window.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener(\'DOMContentLoaded\', recalc, false);

}(window);

分类:

技术点:

相关文章:

  • 2020-01-11
  • 2021-11-07
  • 2021-07-12
  • 2022-01-04
  • 2021-12-23
  • 2021-09-04
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2021-12-31
  • 2021-12-03
  • 2021-12-02
  • 2021-06-18
  • 2021-12-29
  • 2021-08-02
相关资源
相似解决方案