• 适配脚本


    var fixScreen = function() {
        var metaEl = doc.querySelector('meta[name="viewport"]'),
            metaCtt = metaEl ? metaEl.content : '',
            matchScale = metaCtt.match(/initial-scale=([d.]+)/),
            matchWidth = metaCtt.match(/width=([^,s]+)/);
    
        if ( metaEl && !matchScale && ( matchWidth && matchWidth[1] != 'device-width') ) {
            var width = parseInt(matchWidth[1]),
                iw = win.innerWidth || width,
                ow = win.outerWidth || iw,
                sw = win.screen.width || iw,
                saw = win.screen.availWidth || iw,
                ih = win.innerHeight || width,
                oh = win.outerHeight || ih,
                ish = win.screen.height || ih,
                sah = win.screen.availHeight || ih,
                w = Math.min(iw,ow,sw,saw,ih,oh,ish,sah),
                scale = w / width;
    
            if ( scale < 1) {
                metaEl.content += ',initial-scale=' + scale + ',maximum-scale=' + scale + ', minimum-scale=' + scale;
            }
        }
    }
    /**rem**/
    var
    fixScreen = function() { var metaEl = doc.querySelector('meta[name="viewport"]'), metaCtt = metaEl ? metaEl.content : '', matchScale = metaCtt.match(/initial-scale=([d.]+)/), matchWidth = metaCtt.match(/width=([^,s]+)/); if ( !metaEl ) { // REM var docEl = doc.documentElement, maxwidth = docEl.dataset.mw || 750, // 每 dpr 最大页面宽度 dpr = isIos ? Math.min(win.devicePixelRatio, 3) : 1, scale = 1 / dpr, tid; docEl.removeAttribute('data-mw'); docEl.dataset.dpr = dpr; metaEl = doc.createElement('meta'); metaEl.name = 'viewport'; metaEl.content = 'initial-scale=' + ratio + ',maximum-scale=' + ratio + ', minimum-scale=' + scale; docEl.firstElementChild.appendChild(metaEl); var refreshRem = function() { var width = docEl.getBoundingClientRect().width; if (width / dpr > maxwidth) { width = maxwidth * dpr; } var rem = width / 16; docEl.style.fontSize = rem + 'px'; }; //... refreshRem(); } }
  • 相关阅读:
    使用子查询可提升 COUNT DISTINCT 速度 50 倍
    页面装载js及性能分析方法
    用CSS创建打印页面
    每个Web开发者都应该知道的关于URL编码的知识
    C IO programming test code
    全球NTP服务器列表
    MySQL数据的查询注意
    Python使用pyMysql模块插入数据到mysql的乱码解决
    单元测试
    python threading.thread
  • 原文地址:https://www.cnblogs.com/sybboy/p/8884325.html
Copyright © 2020-2023  润新知