北京网站建设|北京网站优化|北京SEO|北京网页设计—逸诚科技http://www.56mp.cn

jQuery结合CSS实现的网页Tab选项卡效果

选项卡效果的效果随处可见,但很少用jQuery+CSS实现的。

今天逸诚科技给大家带来jQuery结合CSS实现的网页Tab选项卡效果,希望大家喜欢。

演示地址:http://www.56mp.cn/upload/Tab/

 Tab选项卡效果

jQuery+CSS实现Tab选项卡效果

 第一步、HTML和CSS

<ul class="tabs">
    <li><a href="#tab1">Gallery</a></li>
    <li><a href="#tab2">Submit</a></li>
</ul>

<div class="tab_container">
    <div id="tab1" class="tab_content">
        <!--Content-->
    </div>
    <div id="tab2" class="tab_content">
       <!--Content-->
    </div>
</div>

在您创建CSS标签之前可能会碰到一些问题,下面是一个常见问题,大多数人会碰到。

Tab选项卡出错

Tab选项卡出错

这里我想出一个解决方案,解决这恼人的问题。看看下面这张图,也看看CSS和其支持的意见,以便更好地理解。

Tab选项卡出错解决方案

Tab选项卡出错解决方案

Tabs CSS

ul.tabs {
margin: 0;
padding: 0;
float: left;
list-style: none;
height: 32px; /*--Set height of tabs--*/
border-bottom: 1px solid #999;
border-left: 1px solid #999;
width: 100%;
}
ul.tabs li {
float: left;
margin: 0;
padding: 0;
height: 31px; /*--Subtract 1px from the height of the unordered list--*/
line-height: 31px; /*--Vertically aligns the text within the tab--*/
border: 1px solid #999;
border-left: none;
margin-bottom: -1px; /*--Pull the list item down 1px--*/
overflow: hidden;
position: relative;
background: #e0e0e0;
}
ul.tabs li a {
text-decoration: none;
color: #000;
display: block;
font-size: 1.2em;
padding: 0 20px;
border: 1px solid #fff; /*--Gives the bevel look with a 1px white border inside the list item--*/
outline: none;
}
ul.tabs li a:hover {
background: #ccc;
}
html ul.tabs li.active, html ul.tabs li.active a:hover  { /*--Makes sure that the active tab does not listen to the hover properties--*/
background: #fff;
border-bottom: 1px solid #fff; /*--Makes the active tab look like it's connected with its content--*/
}

Tab Content CSS

.tab_container {
border: 1px solid #999;
border-top: none;
overflow: hidden;
clear: both;
float: left; width: 100%;
background: #fff;
}
.tab_content {
padding: 20px;
font-size: 1.2em;
}

第二步、激活标签-jQuery

下面的脚本包含注释,解释jQuery动作正在执行。

$(document).ready(function() {

//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content

//On Click Event
$("ul.tabs li").click(function() {

$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});

});

如果您有任何问题,评论或建议,请与我们联系!

标签:jQueryCSS选项卡效果
分类:网站建设| 发布:逸诚科技| 查看: | 发表时间:2009-8-13
原创文章如转载,请注明:转载自逸诚科技 http://www.56mp.cn/
本文链接:http://www.56mp.cn/post/48.html

相关文章

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

1 #逸风
逸风 ”请让与我们“打错字了
此信息出自逸诚科技:http://www.56mp.cn

逸诚科技 于 2009-11-24 17:59:52 回复

已经改过来了,谢谢!
2009-11-24 7:54:48 【REPLY】
2 #ak2009
ak2009 谢谢你们,在这里学到一个很早就想学的技术。
弱弱问一下,这些代码可以免费使用吗?
逸诚科技 于 2009-12-1 11:33:18 回复


弱弱告诉你,本站的所有代码都是免费的。
但转载时请注明出处!

谢谢你对逸诚科技的支持。
2009-11-30 10:11:00 【REPLY】
北京网站建设 | 北京SEO | 关于我们 | 广告合作
Copyright 2009-2010 Powered By 逸诚科技 京ICP备09011301号 
本站所有资料均为逸诚科技原创,转载时请注明版权,谢谢您的合作!