用jQuery的tab实现简单仿微博网页

来源:互联网 发布:月光宝盒 mp3 知乎 编辑:程序博客网 时间:2024/06/16 01:24

页面效果大致如下:

首页效果:



“收藏夹”页面如下:



点击收藏夹页面中的“模块二”效果:



“关注”页面:



“粉丝”页面:




大致页面轮廓就是这样,后期细节还有待加强,代码如下:

HTML代码:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>个人中心</title>    <link rel="stylesheet" href="../css/common.css">    <link rel="stylesheet" href="../css/fans.css"></head><body><!--顶部开始--><div class="head">    <div class="banner">        <table>            <tr>                <td rowspan="4">                    <div class="p-r-25">                        <img  src="../img/3头.png" class="img-round">                    </div>                </td>                <td colspan="3" class="nickname">哈哈哈哈哈哈</td>            </tr>            <tr>                <td colspan="3" class="username">@安娜</td>            </tr>            <tr>                <td width="3%"><div class="sex">女</div></td>                <td width="4%" class="lv">lv.2</td>                <td width="93%"><div class="school">知名搞笑博主</div></td>            </tr>            <tr>                <td colspan="3" class="signature">                    不是因为做不到才没有信心,而是因为没有信心下做不到,路从来都是自己的走出来的。                </td>            </tr>        </table>    </div></div><!--顶部结束--><!--nav部分开始--><div class="outer">    <ul id="tab1" class="nav-text">        <li class="current">主页</li>        <li>相册</li>        <li>收藏夹</li>        <li>设置</li>        <!--此处CSS由于优先级问题只能写在行内-->        <li style="float: right; margin-right: 50px"><p style="margin-top: -10px">粉丝数</p><p style="margin-top: -40px;text-align: center">111</p></li>        <li style="float: right;"><p style="margin-top: -10px">关注数</p><p style="margin-top: -40px;text-align: center">22</p></li>    </ul></div><!--nav部分结束--><!--主容器内容开始--><div  id="content" class="contain">    <div class="cnt">        <!--主页内容-->        <ul style="display: block">            <dl class="cnt-nav nav-text">                <dt>模块一</dt>                <dt>模块二</dt>                <dt>模块三</dt>                <dt>模块四</dt>            </dl>        </ul>        <!--相册内容-->        <ul>            相册        </ul>        <!--收藏夹内容-->        <ul>            <div class="f-l b-f">                <table class="l-h-60 p-l-20">                    <tr>                        <td width="300px">我的收藏</td>                        <td width="30px"><img src="../img/add.png"></td>                    </tr>                    <tr>                        <td>默认收藏夹</td>                        <td >11</td>                    </tr>                    <tr>                        <td>默认收藏夹</td>                        <td>11</td>                    </tr>                </table>            </div>            <div class="f-r b-f">                <dl id="tab2" class="cnt-nav nav-text">                    <dt class="current">模块</dt>                    <dt>模块二</dt>                    <dt>模块三</dt>                    <dt>模块四</dt>                </dl>                <div id="cnt2" style="border-top: solid 10px #e6ecf0">                    <!--动态容器-->                    <p style="display: block">模块一内容</p>                    <!--表白墙容器-->                    <p>模块二内容</p>                    <!--任务容器-->                    <p>模块三内容</p>                    <!--失物招领容器-->                    <p>模块四内容</p>                </div>                <!--<div style="border-top: solid 10px #e6ecf0">                    5555555                </div>                <div style="border-top: solid 10px #e6ecf0">                    333333333                </div>                <div style="border-top: solid 10px #e6ecf0">                    5555555                </div>-->            </div>        </ul>        <!--设置内容-->        <ul>            设置        </ul>        <!--粉丝内容-->        <ul>            <div class="f-l b-f">                <table class="l-h-60 p-l-20">                    <tr>                        <td width="300px">我的粉丝</td>                        <td width="30px"></td>                    </tr>                    <tr>                        <td>粉丝</td>                        <td>22</td>                    </tr>                    <tr>                        <td>黑名单</td>                        <td>22</td>                    </tr>                </table>            </div>            <div class="f-r b-f cnt3">                <p class="all-fan m-l-30 m-t--10">全部粉丝</p>                <table class="m-t-50 m-l-30">                    <tr>                        <td rowspan="4">                            <div class="p-r-25">                                <img  src="../img/2.png" class="fan-img">                            </div>                        </td>                        <td colspan="3" class="fan-nickname">小学小学寻</td>                    </tr>                    <tr>                        <td colspan="3" class="fan-username">@安娜</td>                    </tr>                    <tr>                        <td colspan="3" class="fan-signature">                            呀呀呀呀,哈哈哈                        </td>                    </tr>                </table>                <!--<div style="border-top: solid 10px #e6ecf0">                    333333333                </div>                <div style="border-top: solid 10px #e6ecf0">                    5555555                </div>-->            </div>        </ul>        <!--关注内容-->        <ul>            <div class="f-l b-f">                <table class="l-h-60 p-l-20">                    <tr>                        <td width="300px">我的关注</td>                        <td width="30px"><img src="../img/add.png"></td>                    </tr>                    <tr>                        <td>全部关注</td>                        <td>33</td>                    </tr>                    <tr>                        <td>特别关心</td>                        <td>1</td>                    </tr>                    <tr>                        <td>自定义分组</td>                        <td>33</td>                    </tr>                </table>            </div>            <div class="f-r b-f cnt3">                <p class="all-fan m-l-30 m-t--10">全部关注</p>                <table class="m-t-50 m-l-30">                    <tr>                        <td rowspan="4">                            <div class="p-r-25">                                <img  src="../img/2.png" class="fan-img">                            </div>                        </td>                        <td colspan="3" class="fan-nickname">嘿嘿</td>                    </tr>                    <tr>                        <td colspan="3" class="fan-username">@琳达</td>                    </tr>                    <tr>                        <td colspan="3" class="fan-signature">                            hard and hard                        </td>                    </tr>                </table>                <!--<div style="border-top: solid 10px #e6ecf0">                    333333333                </div>                <div style="border-top: solid 10px #e6ecf0">                    5555555                </div>-->            </div>        </ul>    </div></div><!--主容器结束--><!--整体js--><script src="../js/jquery.js"></script><!--页面js--><script>    /*一级导航JS*/    $(function(){        window.onload = function()        {            var $li = $('#tab1 li');            var $ul = $('#content ul');            var $dt = $('#tab2 dt');            var $p = $('#cnt2 p');            $dt.click(function(){                var $this = $(this);                var $t = $this.index();                $dt.removeClass();                $this.addClass('current');                $p.css('display','none');                $p.eq($t).css('display','block');            });            $li.click(function(){                var $this = $(this);                var $t = $this.index();                $li.removeClass();                $this.addClass('current');                $ul.css('display','none');                $ul.eq($t).css('display','block');            })        }    });    /* /!*二级导航JS*!/     $(function(){     window.onload = function()     {     var $dt = $('#tab2 dt');     var $p = $('#cnt3 p');     $dt.click(function(){     var $this = $(this);     var $t = $this.index();     $dt.removeClass();     $this.addClass('current');     $p.css('display','none');     $p.eq($t).css('display','block');     })     }     });     */</script></body></html>

公告部分样式CSS:

/*2017年12月14日整理公用css样式:包含头部,导航,主容器,以及一些公用样式如:m-t-10 等于 margin-top:10px*/*{    margin: 0;    padding: 0;}body{    background:#e6ecf0;}/*全局公用样式*/.f-l{    float: left;}.f-r{    float: right;}.p-r-25{    padding-right: 25px;}.m-t--10{    margin-top: 10px;}.l-h-60{    line-height:60px;}.b-f{    background: #ffffff;}.m-t-50{    margin-top: 50px;}.m-l-30{    margin-left: 30px;}.m-l-20{    margin-left: 20px;}.p-l-20{    padding-left: 20px;}/*顶部样式*/.head{    height: 250px;    /*background-image: url("../img/head.png");*/    background: #999999;    background-size: 100% 100%;}.banner{    width: 100%;    height: 220px;    margin: 0 auto 0 auto;}.img-round{    width: 120px;    height:120px;    border-radius: 120px 120px 120px 120px;}.banner table{    padding-top: 80px;    margin-left: 30px;}.nickname{    font-family: 微软雅黑;    font-size: 24px;    color: #ffffff;    font-weight: bold;}.username{    font-family: 微软雅黑;    font-size: 14px;    color: #EEEEEE;    line-height: 30px;}.sex{    font-family: 微软雅黑;    font-size: 14px;    color: #ffffff;    text-align: center;    /*性别女背景色*/    background: #fcb9ba;    /*    !*性别男背景色*!    background: #00b7ee;    */    width: 22px;    height:22px;    border-radius: 22px 22px 22px 22px;}.lv{    font-family: 微软雅黑;    font-size: 14px;    color: #ffffff;    text-align: center;    background: #f5894e;    height:0.1px;    border-radius: 8px 8px 8px 8px;}.school{    font-family: 微软雅黑;    font-size: 14px;    color: #ffffff;    /*font-weight: bold;*/    text-align: center;    background: #08c25b;    width: 9%;/*宽度不能根据字数变化而变化,把div改成span可以解决,但会有一些小问题。待定*/    height: 22px;    border-radius: 8px 8px 8px 8px;    margin-left: 15px;}.signature{    font-family: 微软雅黑;    font-size: 16px;    color: #ffffff;    font-weight: bold;    line-height: 50px;}/*导航样式*/.outer {    width:100%;}ul{    list-style-type: none;}#tab1 {    overflow:hidden;    zoom:1;    background:#fff;    height: 50px;}#tab1 li {    float:left;    color:#333333;    height:48px;    cursor:pointer;    line-height:60px;    padding:0 35px;}#tab1 li.current {    border-bottom: solid 2px #00a0e9;}#content {    border-top-width:0;}#content ul {    line-height:25px;    display:none;    margin:0 30px;    padding:10px 0;}.nav-text{    font-family: 微软雅黑;    font-size: 16px;    color: #ededed;}/*二级导航*/.cnt-nav {    overflow:hidden;    zoom:1;    background:#fff;    /*height: 50px;*/    /*border:1px solid #000;*/}.cnt-nav dt {    float:left;    color:#333333;    height:48px;    cursor:pointer;    line-height:48px;    padding:0 70px;}/*主容器*/.contain{    width: 1170px;    height: 600px;    margin: 20px auto 0 auto;    /*background: #08c25b;*/}.cnt{    width: 1170px;    /*height: 600px;*/    background: #e6ecf0;    /*margin: 20px auto 0 auto;*/}/*二级容器*//*#tab2 {    overflow:hidden;    zoom:1;    background:#fff;    height: 50px;}*//*#tab2 dt {    float:left;    color:#333333;    height:48px;    cursor:pointer;    line-height:60px;    padding:0 35px;}*/#tab2 dt.current {    border-bottom: solid 2px #00a0e9;}#cnt2 {    border-top-width:0;    width: 740px;}#cnt2 p{    display:none;}.cnt3{    width: 740px;}

粉丝和关注部分CSS

.fan-img{    width: 80px;    height:80px;    border-radius: 80px 80px 80px 80px;}.fan-nickname{    font-family: 微软雅黑;    font-size: 20px;    color: #5a5a5a;    font-weight: bold;}.fan-username{    font-family: 微软雅黑;    font-size: 12px;    color: #5a5a5a;    line-height: 30px;}.fan-signature{    font-family: 微软雅黑;    font-size: 14px;    color: #828282;    font-weight: bold;    line-height: 50px;}.all-fan{    font-family: 微软雅黑;    font-size: 18px;    color: #5e5e5e;}


原创粉丝点击