zoukankan      html  css  js  c++  java
  • js-YDUI 移动端解决方案

    /**
     * YDUI 可伸缩布局方案
     * rem计算方式:设计图尺寸px / 100 = 实际rem  例: 100px = 1rem
     */
    !function (window) {
    
        /* 设计图文档宽度 */
        var docWidth = 750;
    
        var doc = window.document,
            docEl = doc.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
    
        var recalc = (function refreshRem () {
            var clientWidth = docEl.getBoundingClientRect().width;
            //getBoundingClientRect(); 这个方法返回一个矩形对象,包含四个属性:left、top、right和bottom。分别表示元素各边与页面上边和左边的距离。
    
            /* 8.55:小于320px不再缩小,11.2:大于420px不再放大 */
            docEl.style.fontSize = Math.max(Math.min(20 * (clientWidth / docWidth), 11.2), 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);
     
  • 相关阅读:
    es6 yield简单使用
    es6 generator 函数中的yield理解
    es6 promise的使用,同时处理多个异步请求
    es6 filter的使用
    ES6中reduce的计算过程
    es6函数的参数展开
    搭建基于express框架的运行环境
    通过node.js搭建服务,访问html静态页面
    docker compose
    JDBCUtil
  • 原文地址:https://www.cnblogs.com/intelwisd/p/7505410.html
Copyright © 2011-2022 走看看