tab切换jquery代码

时间:2023-03-09 00:11:14
tab切换jquery代码

http://immmmm.com/jquery-tab-switch-code-improved.html

html

<div id="sidebar-tab">
 
<div id="tab-title">
 
<h3><span class="selected">最新评论</span><span>近期热评</span><span>随机文章</span></h3>
 
</div>
 
<div id="tab-content">
 
<ul><?php wkc_recent_comments('number=10&length=25'); ?></ul>
 
<ul class="hide"><?php wkc_most_commented_posts('number=10&days=300'); ?></ul>
 
<ul class="hide"><?php wkc_random_posts('number=10&length=40'); ?></ul>
 
</div>
 
</div> css
#sidebar-tab{border:1px solid #ccf;margin-bottom:1.5em;overflow:hidden;}
 
#tab-title h3{color:#666;font-size:15px;font-weight:400;}
 
#tab-title .selected{color:#356aa0;border-bottom:0px;} /*标题被选中时的样式*/
 
#tab-title span{padding:5px 9px 5px 10px;border:1px solid #ccf;border-right:0px;margin-left:-1px;cursor:pointer;}
 
#tab-content .hide{display:none;} /*默认让第一块内容显示,其余隐藏*/
 
#tab-content ul{padding:5px 10px;overflow:hidden;}
 
#tab-content ul li{padding-top:5px;height:20px;} jquery
 
$('#tab-title span').mouseover(function(){
 
$(this).addClass("selected").siblings().removeClass();
 
$("#tab-content > ul").eq($('#tab-title span').index(this)).show().siblings().hide();
 
});

改进jquery

$('#tab-title span').click(function(){
 
$(this).addClass("selected").siblings().removeClass();
 
$("#tab-content > ul").slideUp('1500').eq($('#tab-title span').index(this)).slideDown('1500');
 
});