jQuery實(shí)現(xiàn)簡單漂亮的Nav導(dǎo)航菜單效果
本文實(shí)例講述了jQuery實(shí)現(xiàn)簡單漂亮的Nav導(dǎo)航菜單效果。分享給大家供大家參考,具體如下:
自己寫的一個(gè)簡單的導(dǎo)航菜單,先看效果:

鼠標(biāo)懸浮時(shí)菜單項(xiàng)向上移動(dòng)成藍(lán)底白字,點(diǎn)擊之后底部會有藍(lán)條表示當(dāng)前選中項(xiàng)。
頁面代碼,菜單的每一項(xiàng)都是一個(gè) div ,其中包括一個(gè) ul 用來放置顯示文字等,另一個(gè) div 則是底部的藍(lán)條,需要給第一項(xiàng)和最后一項(xiàng)設(shè)置不同的 class ,樣式需要用到:
<div id="nav">
<div class="navItem indexNavItem">
<ul class="navUl">
<li>首頁</li>
<li class="hoverLi">首頁</li>
</ul>
<div class="highlighter selectedNav"></div>
</div>
<div class="navItem">
<ul class="navUl">
<li>A</li>
<li class="hoverLi">A</li>
</ul>
<div class="highlighter"></div>
</div>
<div class="navItem lastNavItem">
<ul class="navUl">
<li>A</li>
<li class="hoverLi">A</li>
</ul>
<div class="highlighter"></div>
</div>
<div id="logoutNavItem" class="navItem logoutNavItem lastNavItem">
<ul class="navUl">
<li>退出</li>
<li class="hoverLi">退出</li>
</ul>
<div class="highlighter"></div>
</div>
</div>
樣式,主要就是每個(gè)菜單項(xiàng)的左右邊框的設(shè)置以及 ul 和 li 的位置設(shè)置:
*
{
padding: 0;
margin: 0;
}
body
{
background-color: #fffff3;
font: 12px/1.6em Helvetica, Arial, sans-serif;
}
ul,li{
list-style: none;
}
#nav
{
text-align: center;
height: 50px;
font-size: 10px;
line-height: 30px;
background-color: #F0E6DB;
margin-bottom: 10px;
}
.navItem
{
cursor: pointer;
position: relative;
float: left;
width: 100px;
height: 50px;
font-size: 15px;
border-right: 2px solid rgb(255,255,255);
border-left: 2px solid rgb(255,255,255);
overflow: hidden;
font-weight:bold;
}
.indexNavItem
{
border-left: 4px solid rgb(255,255,255);
margin-left: 10px;
}
.lastNavItem
{
border-right: 4px solid rgb(255,255,255);
}
.logoutNavItem
{
float: right;
width: 120px;
margin-right: 10px;
border-left: 4px solid rgb(255,255,255);
}
.navUl
{
position: relative;
height: 100px;
width: 100%;
border-bottom: 5px solid rgb(2,159,212);
}
.navUl li
{
height: 50px;
line-height: 50px;
}
.highlighter
{
position: absolute;
bottom: 0;
height: 5px;
width: 100%;
}
.selectedNav
{
background-color: #029FD4;
}
.hoverLi
{
background-color: #029FD4;
color: #ffffff;
}
接下來就是給菜單編寫懸浮和單擊事件的 js 代碼了,懸浮時(shí)將 ul 上移 li 的高度,鼠標(biāo)移開后再恢復(fù),點(diǎn)擊之后就是給藍(lán)條的 div 添加樣式即可:
$(function() {
$(".navItem").hover(function() {
$(this).children("ul").animate({
top: "-50px"
}, 100);
}, function() {
$(this).children("ul").animate({
top: "0px"
}, 100);
});
$(".navItem").click(function(event) {
$(this).siblings().children('.highlighter').removeClass('selectedNav');
$(this).children('.highlighter').addClass('selectedNav');
});
})
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery和CSS仿京東仿淘寶列表導(dǎo)航菜單
- 基于jQuery實(shí)現(xiàn)火焰燈效果導(dǎo)航菜單
- jQuery縱向?qū)Ш讲藛涡Ч麑?shí)現(xiàn)方法
- jQuery+CSS3實(shí)現(xiàn)仿花瓣網(wǎng)固定頂部位置帶懸浮效果的導(dǎo)航菜單
- jQuery+css實(shí)現(xiàn)非常漂亮的水平導(dǎo)航菜單效果
- jQuery模仿京東/天貓商品左側(cè)分類導(dǎo)航菜單效果
- 原生js和jquery分別實(shí)現(xiàn)橫向?qū)Ш讲藛涡Ч?/a>
- jQuery+CSS實(shí)現(xiàn)一個(gè)側(cè)滑導(dǎo)航菜單代碼
- jquery實(shí)現(xiàn)具有收縮功能的垂直導(dǎo)航菜單
- 基于jQuery實(shí)現(xiàn)以手風(fēng)琴方式展開和折疊導(dǎo)航菜單
- jQuery實(shí)現(xiàn)二級導(dǎo)航菜單的示例
相關(guān)文章
Jquery遍歷checkbox獲取選中項(xiàng)value值的方法
這篇文章主要介紹了Jquery遍歷checkbox獲取選中項(xiàng)的value值,需要的朋友可以參考下2014-02-02
表頭固定(利用jquery實(shí)現(xiàn)原理介紹)
表頭固定應(yīng)該是一個(gè)用得比較多的功能,參考了網(wǎng)上幾個(gè)例子,在幾個(gè)常用瀏覽器下顯示不是很完美2012-11-11
jQuery實(shí)現(xiàn)鼠標(biāo)滑過預(yù)覽圖片大圖效果的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)滑過預(yù)覽圖片大圖效果的方法,涉及jQuery鼠標(biāo)事件響應(yīng)及頁面元素屬性動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-04-04
jQuery中彈出iframe內(nèi)嵌頁面元素到父頁面并全屏化的實(shí)例代碼
這篇文章主要介紹了jQuery中彈出iframe內(nèi)嵌頁面元素到父頁面并全屏化的實(shí)例代碼,需要的朋友可以參考下2016-12-12
基于jquery的點(diǎn)擊鏈接插入鏈接內(nèi)容的代碼
基于jquery的點(diǎn)擊鏈接插入鏈接內(nèi)容的代碼,感覺有bug,解決的朋友可以留言方便更多的朋友2012-07-07
jQuery實(shí)現(xiàn)Flash效果上下翻動(dòng)的中英文導(dǎo)航菜單代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)Flash效果上下翻動(dòng)的中英文導(dǎo)航菜單代碼,實(shí)例分析了jQuery基于鼠標(biāo)hover事件控制頁面元素動(dòng)畫效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09

