页面常用代码整理

在页面不够高的时候,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站空间根目录
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容