JQuery標(biāo)簽頁效果的兩個實例講解(4)
按照慣例,我們還是先來看一下最終要達到效果圖:

和上一個菜單效果類似,當(dāng)鼠標(biāo)移動到標(biāo)簽上的時候,下面會顯示相應(yīng)的內(nèi)容。當(dāng)然,同樣存在滑動門的問題。
前臺頁面的代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tab.aspx.cs" Inherits="tab" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/tab.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="js/tab.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="firstDiv">
<ul>
<li class="tabin">標(biāo)簽一</li>
<li>標(biāo)簽二</li>
<li>標(biāo)簽三</li>
</ul>
<div class="contentin">
我是標(biāo)簽一的內(nèi)容</div>
<div>
我是標(biāo)簽二的內(nèi)容</div>
<div>
我是標(biāo)簽三的內(nèi)容</div>
</div>
</form>
</body>
</html>
tab.css
ul,li
{
list-style:none;
margin:0;
padding:0;
}
li
{
background-color:#6E6E6E;
float:left;
color:White;
padding:5px;
margin-right:3px;
border: 1px solid white;
}
.tabin
{
border:1px solid #6E6E6E;
}
#firstDiv div
{
clear:left;
background-color:#6E6E6E;
width:200px;
height:100px;
display:none;
}
#firstDiv .contentin
{
display:block;
}
tab.js
/// <reference path="jquery-1.9.1.min.js" />
$(document).ready(function () {
var setTimeouId;
$("#firstDiv li").each(function (index) {
$(this).mouseover(function () {
var nodeTabin = $(this);
setTimeouId = setTimeout(function () {
$("#firstDiv .contentin").removeClass("contentin");
$("#firstDiv .tabin").removeClass("tabin");
$("#firstDiv div").eq(index).addClass("contentin");
//我在這里犯錯了哦,不應(yīng)該再用this this如果用在這里的話那么是指的window
nodeTabin.addClass("tabin");
}, 300);
}).mouseout(function () {
clearTimeout(setTimeouId);
});
});
});
我們最終實現(xiàn)的效果如圖所示:

當(dāng)單擊標(biāo)簽一的時候,下面加載的是一個html的全部內(nèi)容;當(dāng)單擊標(biāo)簽二的時候,下面加載的是一個asp.net頁面的一部分內(nèi)容,標(biāo)簽三未添加效果。
頁面前臺的代碼如圖:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tab.aspx.cs" Inherits="tab" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/tab.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/tab.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="firstDiv">
<ul>
<li class="tabin">標(biāo)簽一</li>
<li>標(biāo)簽二</li>
<li>標(biāo)簽三</li>
</ul>
<div class="contentin">
我是標(biāo)簽一的內(nèi)容</div>
<div>
我是標(biāo)簽二的內(nèi)容</div>
<div>
我是標(biāo)簽三的內(nèi)容</div>
</div>
<br />
<br />
<br />
<div id="secondDiv">
<ul>
<li class="tabin">標(biāo)簽一</li>
<li>標(biāo)簽二</li>
<li>標(biāo)簽三</li>
</ul>
<div id="secondContentin">
<img alt="裝載中" src="images/img-loading.gif" />
<div id="realContentin"></div>
</div>
</div>
</form>
</body>
</html>
tab.css
ul,li
{
list-style:none;
margin:0;
padding:0;
}
#firstDiv li
{
background-color:#6E6E6E;
float:left;
color:White;
padding:5px;
margin-right:3px;
border: 1px solid white;
}
#firstDiv .tabin
{
border:1px solid #6E6E6E;
}
#firstDiv div
{
clear:left;
background-color:#6E6E6E;
width:200px;
height:100px;
display:none;
}
#firstDiv .contentin
{
display:block;
}
#secondDiv li
{
float:left;
color:Blue;
background-color:White;
padding:5px;
margin-right:3px;
/*當(dāng)鼠標(biāo)放在標(biāo)簽上時,顯示成小手*/
cursor:pointer;
}
#secondDiv li.tabin
{
background-color:#F2F6F8;
border:1px solid black;
border-bottom:0;
/*只有position設(shè)置成relative或者absolute的時候z-index才有效*/
position:relative;
z-index:100;
}
#secondContentin
{
width:300px;
height:200px;
padding:10px;
background-color:#F2F6F8;
clear:left;
border:1px solid black;
/*下面是讓底下的內(nèi)容向上移動一個像素
*但是,我們可以看到,并沒有達到我們想要的效果,接下
*來要上上面的li顯示層次在最上面,這樣就蓋住了下面的div的border
*/
position:relative;
top:-1px;
}
/*開始的時候讓loading圖片隱藏*/
img
{
display:none;
}
關(guān)于z-index的問題,注釋上有說明,下面的截圖是我截的js手冊上的內(nèi)容:
tab.js
/// <reference path="jquery.js" />
$(document).ready(function () {
var setTimeouId;
$("#firstDiv li").each(function (index) {
$(this).mouseover(function () {
var nodeTabin = $(this);
setTimeouId = setTimeout(function () {
$("#firstDiv .contentin").removeClass("contentin");
$("#firstDiv .tabin").removeClass("tabin");
$("#firstDiv div").eq(index).addClass("contentin");
//我在這里犯錯了哦,不應(yīng)該再用this this如果用在這里的話那么是指的window
nodeTabin.addClass("tabin");
}, 300);
}).mouseout(function () {
clearTimeout(setTimeouId);
});
});
$("#realContentin").load("HTMLPage.htm");
$("#secondDiv li").each(function (index) {
$(this).click(function () {
/*更改樣式*/
$("#secondDiv li.tabin").removeClass("tabin");
$(this).addClass("tabin");
if (index == 0) {
$("#realContentin").load("HTMLPage.htm");
} else if (index == 1) {
$("#realContentin").load("Default.aspx div");
} else if (index == 2) {
}
});
});
//我剛開始的時候用的是jquery的最新版本,但是出現(xiàn)了無法綁定的問題。
$("#secondContentin img").bind("ajaxStart", function () {
$(this).show();
}).bind("ajaxStop", function () {
//setTimeout(function(){$(this).hide()},300);
$(this).hide(1000);
});
});
在這里,我想提一下,就是我開始的時候,用的是jquery-1.9.1.min.js,但是在綁定ajax事件的時候,無法綁定,可以綁定click事件。
所以,我建議大家不要用最新版的jquery,避免出現(xiàn)一些莫名其妙的問題。
以上兩種標(biāo)簽頁效果,希望小編整理的這篇文章可以幫助到大家。
- js與jquery分別實現(xiàn)tab標(biāo)簽頁功能的方法
- jQuery實現(xiàn)簡單的tab標(biāo)簽頁效果
- 基于jQuery實現(xiàn)多標(biāo)簽頁切換的效果(web前端開發(fā))
- JQuery標(biāo)簽頁效果實例詳解
- jQuery EasyUI 布局之動態(tài)添加tabs標(biāo)簽頁
- jQuery EasyUI API 中文文檔 - Tabs標(biāo)簽頁/選項卡
- jquery tab標(biāo)簽頁的制作
- JS實現(xiàn)標(biāo)簽頁效果(配合css)
- 一個js隨機顏色腳本(用于標(biāo)簽頁面,也可用于任何頁面)
- jQuery實現(xiàn)標(biāo)簽頁效果實戰(zhàn)(4)
相關(guān)文章
jquery,js簡單實現(xiàn)類似Angular.js雙向綁定
本文主要介紹了jquery,js簡單實現(xiàn)類似Angular.js雙向綁定的方法。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01
jQuery實現(xiàn)的form轉(zhuǎn)json經(jīng)典示例
這篇文章主要介紹了jQuery實現(xiàn)的form轉(zhuǎn)json功能,結(jié)合完整實例形式分析了jQuery將form表單數(shù)據(jù)封裝成json傳輸?shù)木唧w步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
使用jQuery+EasyUI實現(xiàn)CheckBoxTree的級聯(lián)選中特效
這篇文章主要介紹了使用jQuery+EasyUI實現(xiàn)CheckBoxTree的級聯(lián)選中特效的相關(guān)資料,需要的朋友可以參考下2015-12-12
jQuery post數(shù)據(jù)至ashx實例詳解
這篇文章主要介紹了jQuery post數(shù)據(jù)至ashx實例詳解的相關(guān)資料,需要的朋友可以參考下2016-11-11
自定義jquery模態(tài)窗口插件無法在頂層窗口顯示問題
自定義一個jquery模態(tài)窗口插件只能在mainFrame窗口中顯示,無法在頂層窗口顯示2014-05-05

