zoukankan      html  css  js  c++  java
  • 通过改变viewport 实现网站自适应

         var phoneWidth = parseInt(window.screen.width);
        var phoneScale = phoneWidth/640;
        var userAgent = navigator.userAgent;   
        var index = userAgent.indexOf("Android");
        if(index >= 0){  
        var androidVersion = parseFloat(userAgent.slice(index+8));
            if(androidVersion>2.3){
                $("head").eq(0).append("<meta name='viewport' content='width=640, initial-scale = "+phoneScale+", minimum-scale = "+phoneScale+", maximum-scale = "+phoneScale+",user-scalable=no, target-densitydpi=device-dpi'>");
            }else{
                $("head").eq(0).append("<meta name='viewport' content='width=640, target-densitydpi=device-dpi'>");
            }
    
        }else{
            $("head").eq(0).append("<meta name='viewport' content='width=640, initial-scale = "+phoneScale+", minimum-scale = "+phoneScale+", maximum-scale = "+phoneScale+",user-scalable=no, target-densitydpi=device-dpi'>");
        }

     2. 使用rem实现自适应http://caibaojian.com/web-app-rem.html

    3.优化js

    (function(a, d) {
            var b = a.documentElement,
                e = "orientationchange" in window ? "orientationchange" : "resize",
                c = function() {
                    var a = b.clientWidth;
                    a && (b.style.fontSize = Math.min(a, 640) / 320 * 100 + "px")
                };
                css = document.createElement('style');
                css.type="text/css";
                css.innerHTML = "html {font-size:"+Math.min(b.clientWidth, 640) / 320 * 100+"px}";
                a.getElementsByTagName('head')[0].appendChild(css);
            a.addEventListener && (d.addEventListener(e, c, !1), a.addEventListener("DOMContentLoaded", c, !1));
        })(document, window);
  • 相关阅读:
    Philosopher(set 线段树合并)
    [NOI2013]书法家
    [NOI2013]树的计数
    [NOI2013]向量内积
    对于有关东方的题目的整理。。
    BZOJ 1412: [ZJOI2009]狼和羊的故事
    BZOJ 1877: [SDOI2009]晨跑
    BZOJ 2039: [2009国家集训队]employ人员雇佣
    BZOJ 1934: [Shoi2007]Vote 善意的投票
    BZOJ 1070: [SCOI2007]修车
  • 原文地址:https://www.cnblogs.com/cainiaoz/p/5160769.html
Copyright © 2011-2022 走看看