• 判断pc端还是移动,并给移动加上其它的样式文件方法


    所有移动端PC端 按 640 进行排版

    body, html {
     100%;
    height: 100%;
    overflow: hidden;
    background-color: #515363;
    }
    body{
    height: 100%;
    overflow: hidden;
    box-shadow: 0 0 160px 0 #5C99E7;
    background-color: #fff;
    position:relative;
    }
    .app {
     640px;
    margin: 0 auto;
    box-sizing: border-box;
    overflow:hidden;
    }
    
    <body class="app"></div>
    
    
     <script type="text/javascript">
        if(/Android (d+.d+)/.test(navigator.userAgent)){
            var version = parseFloat(RegExp.$1);
            if(version>2.3){
                var phoneScale = parseInt(window.screen.width)/640;
                document.write('<meta name="viewport" content="width=640, minimum-scale = '+ phoneScale +', maximum-scale = '+ phoneScale +', target-densitydpi=device-dpi">');
            }else{
                document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');
            }
        }else{
            document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
        }
        //微信去掉下方刷新栏
        if(navigator.userAgent.indexOf('MicroMessenger') >= 0){
            document.addEventListener('WeixinJSBridgeReady', function() {
                //WeixinJSBridge.call('hideToolbar');
            });
        }
        </script>

    ************移动pc端分别加载不同的网页方法***************

    <script>
    function isMobile(){try{var $=window.location.hash;if(!$.match("fromapp"))if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad|Mobile)/i)))return true}catch(_){}return false}
    !!isMobile()&&(document.location.href="./mobile/");
    if(!-[1,]){document.location.href="./html/"};
    </script>

    1、<script>
    function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
    if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
    }
    return flag;
    }
    if (!IsPC()) {
    <%--respond样式--%>
    $("head").append('<link href="/Css/media.css" rel="stylesheet" />');

    }
    </script>

    2、meta name="viewport" 的设置方法

    <script type="text/javascript">
    	if(/Android (d+.d+)/.test(navigator.userAgent)){
    		var version = parseFloat(RegExp.$1);
    		if(version>2.3){
    			var phoneScale = parseInt(window.screen.width)/640;
    			document.write('<meta name="viewport" content="width=640, minimum-scale = '+ phoneScale +', maximum-scale = '+ phoneScale +', target-densitydpi=device-dpi">');
    		}else{
    			document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');
    		}
    	}else{
    		document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
    	}
    
    </script>
    

      

  • 相关阅读:
    HDU 1874 畅通工程续 (Dijkstra , Floyd , SPFA, Bellman_Ford 四种算法)
    HDU Wooden Sticks
    HDU 3664 Permutation Counting
    javascript DOM添加元素,使用节点属性
    SQL server查询数据类型为ntext是空或NULL值
    TSQL Pivot Tables(行列转换) in SQL Server 2005/2008
    ASP.NET 3.5(c#)区域化设置(LCID)
    Sql 脚本导入EXCEL数据
    asp.net 3.5 csharp 实现事务
    asp.net3.5 csharp: How to show HTML content in calendar tooltip?
  • 原文地址:https://www.cnblogs.com/aimyfly/p/4350494.html
Copyright © 2020-2023  润新知