美文网首页
页面常用代码整理

页面常用代码整理

作者: __拾光__ | 来源:发表于2018-04-18 17:44 被阅读0次

    在页面不够高的时候,footer永远保持在底部的css代码

    <body class="main">
       <header></header>
       <content></content>
       <footer></footer>
    </body>
    .main {
      display: flex;
      min-height: 100vh;
      flex-direction: column;
    }
     
    header {
      background: red;
      min-height: 100px;
    }
     
    content {
      background: blue;
      flex: 1;  /* 1代表最大 */
    }
     
    footer {
      background: green;
      min-height: 100px;
    }
    

    导航栏的active的js代码

    $(document).ready(function () {
        var a = document.URL;
        $(".nav ul li").each(function () {
            var b = $(this).children("a")[0].href;
            if (a == b) {
                $(this).children("a").parent().addClass("active");
            }
            else {
                $(this).children("a").parent().removeClass("active");
            }
        })
    })
    

    banner大图的自适应js代码

    $(function(){
        $(".bd img").css("display","none")
        $(".bd li").each(function(e){
        $(".bd li:eq("+e+")").css("backgroundImage", "url(" + $(".bd li:eq("+e+")").find("img").attr("src") + ")");
        });
    })
    

    PC站跳转移动站

    <script type="text/javascript">
        function browserRedirect() {
            var sUserAgent = navigator.userAgent.toLowerCase();
            var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
            var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
            var bIsMidp = sUserAgent.match(/midp/i) == "midp";
            var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
            var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
            var bIsAndroid = sUserAgent.match(/android/i) == "android";
            var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
            var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    
            if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
                window.location.href = 'm/index.html';
            } else {
                
            }
        }
        browserRedirect();  
    </script>  
    
    请将以上代码装到pc站首页文件中<head>后面  
    m文件夹直接上传至pc站空间根目录
    

    相关文章

      网友评论

          本文标题:页面常用代码整理

          本文链接:https://www.haomeiwen.com/subject/hykbkftx.html