zoukankan      html  css  js  c++  java
  • 前端移动端相关的代码(pc端与移动端自动切换)

     一、PC端与移动端自动切换相应的链接地址

    <script type="text/javascript">
    $(function(){
    try {
    var urlhash = window.location.hash;
    if (!urlhash.match("fromapp")){
    //移动端
    if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))){

    window.location.href='/cn/index.htm';
    //pc端
    }else{
    window.location.href='/cn/index.htm';
    }
    }
    }catch(err){}
    });
    </script>

     二、媒体查询关键代码

    一共需要两步(head里面加meta+媒体查询的尺寸限制)

       2.1 head里面的代码

    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">

      2.2 需要写的代码

    /*只有在PC下才执行的样式*/
    @media screen and (min- 992px) {
        h1 {
            font-size: 36px;
            margin: 30px 0 10px 0;
        }
        .box {
            border: 1px solid #a33;
            color: #a33;
            background-color: #fee;
            margin: 10px;
            padding: 10px;
        }
    }
    /*只有在PAD下才执行的样式*/
    @media screen and (min- 768px) and (max- 992px) {
        h1 {
            font-size: 28px;
            margin: 20px 0 10px 0;
        }
        .box {
            border: 1px solid #3a3;
            color: #3a3;
            background-color: #efe;
            margin: 10px;
            padding: 10px;
        }
    }
    /*只有在PHONE下才执行的样式*/
    @media screen and (max- 767px) {
        h1 {
            /*font-size: 28px;
            margin: 20px 0 10px 0;*/
            display: none;
        }
        .box {
            border: 1px solid #33a;
            color: #33a;
            background-color: #eef;
            margin: 10px;
            padding: 10px;
        }
    }

    三、rem的使用方法

    操作步骤:

    haley欢迎您来访本博客。此博客是作者在工作中的一个记事本,方便下次遇到同样问题时,以最快的速度解决掉遇到的问题。如果您发现哪里写的不对,欢迎给我留言,让我们一起进步。不胜感激!
  • 相关阅读:
    URL编码及解码
    Javascript解析URL
    为什么在JavaScript中0.1+0.2不等于0.3?
    void 0 与 undefined
    Windows7、Windows10下把Git Bash Here 添加到右键菜单(ContextMenu)
    [菜鸟]C++创建类对象时(无参)后不加括号与加括号的区别
    git常用命令
    git 出错及解决
    Vim升华之树形目录插件NERDTree安装图解
    rails.vim环境安装(ubuntu)
  • 原文地址:https://www.cnblogs.com/haley168/p/phone-1.html
Copyright © 2011-2022 走看看