Jquery中文网 www.jquerycn.cn
Jquery中文网 >  jQuery  >  jquery 教程  >  正文 基于jquery自己写tab滑动门(通用版)

基于jquery自己写tab滑动门(通用版)

发布时间:2013-10-05   编辑:www.jquerycn.cn
今天与大家分享一下,自己写的滑动门。在网上也搜索了一下,没发现比较好的,于是乎自己写一吧~写起来也很简单,为了方便使用,我已经尽量封装好了。好吧,闲话少说,直接上代码吧
css:
复制代码 代码如下:

.main
{
height:360px;
width:290px;
border:1px solid #444444;
font-size:12px;
color:#444444;
margin:20px;
}
.main_top
{
height:30px;
width:290px;
line-height:30px;
text-align:left;
background-color:#999999;
border-bottom:1px solid #444444;
}
.main_top ul
{
padding:0px;
margin:0px;
list-style-type:none;
position:absolute;
}
.main_top ul li.h_qian
{
float:left;
width:80px;
text-align:center;
background-color:#999999;
height:30px;
}
.main_top ul li.h_hou
{
float:left;
width:80px;
text-align:center;
background-color:#ffffff;
cursor:pointer;
margin-top:1px;
height:30px;
font-weight:bold;
}
.main_content
{
margin:10px;
}

 js:
复制代码 代码如下:

function tabchange(obj,p,c,q,h) {
$(obj).parent().find("li").attr("class", ""+q+"");
$(obj).parents("."+p+"").find("."+c+"").hide();
$(obj).attr("class", ""+h+"");
var j = $(obj).index();
$(obj).parents("."+p+"").find("."+c+":eq(" + j + ")").show();
}

html:
复制代码 代码如下:

<div class="main">
<div class="main_top">
<ul>
<li class="h_hou" onmouseover="tabchange(this,'main','main_content','h_qian','h_hou')">第一模块</li>
<li class="h_qian" onmouseover="tabchange(this,'main','main_content','h_qian','h_hou')">第二模块</li>
<li class="h_qian" onmouseover="tabchange(this,'main','main_content','h_qian','h_hou')">第三模块</li>
</ul>
</div>
<div class="main_content">第1块
</div>
<div class="main_content" style="display:none;">第2块
</div>
<div class="main_content" style="display:none;">第3块
</div>
</div>

代码很简单,不多说了,详细使用方法请参照Demo中tangtab.js里的注释。

附:
在线演示:http://demo.jb51.net/js/2012/TabDemo/
打包下载:TabDemo_jb51.rar

您可能感兴趣的文章:
基于jquery自己写tab滑动门(通用版)
基于JQuery的6个Tab选项卡插件
EasySlider 基于jQuery功能强大简单易用的滑动门插件
idTabs基于JQuery的根据URL参数选择Tab插件
40个有创意的jQuery图片、内容滑动及弹出插件收藏集之一
用jQuery打造TabPanel效果代码
基于jQuery图片平滑连续滚动插件
40个有创意的jQuery图片和内容滑动及弹出插件收藏集之二
玩转jQuery按钮 请告诉我你最喜欢哪些?
触摸设备的日期选择插件 Mobiscroll

关键词: tab  滑动门   
[关闭]