jQuery實現(xiàn)簡單漂亮的Nav導(dǎo)航菜單效果
本文實例講述了jQuery實現(xiàn)簡單漂亮的Nav導(dǎo)航菜單效果。分享給大家供大家參考,具體如下:
自己寫的一個簡單的導(dǎo)航菜單,先看效果:
鼠標懸浮時菜單項向上移動成藍底白字,點擊之后底部會有藍條表示當前選中項。
頁面代碼,菜單的每一項都是一個 div ,其中包括一個 ul 用來放置顯示文字等,另一個 div 則是底部的藍條,需要給第一項和最后一項設(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>
樣式,主要就是每個菜單項的左右邊框的設(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 代碼了,懸浮時將 ul 上移 li 的高度,鼠標移開后再恢復(fù),點擊之后就是給藍條的 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擴展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- jQuery和CSS仿京東仿淘寶列表導(dǎo)航菜單
- 基于jQuery實現(xiàn)火焰燈效果導(dǎo)航菜單
- jQuery縱向?qū)Ш讲藛涡Ч麑崿F(xiàn)方法
- jQuery+CSS3實現(xiàn)仿花瓣網(wǎng)固定頂部位置帶懸浮效果的導(dǎo)航菜單
- jQuery+css實現(xiàn)非常漂亮的水平導(dǎo)航菜單效果
- jQuery模仿京東/天貓商品左側(cè)分類導(dǎo)航菜單效果
- 原生js和jquery分別實現(xiàn)橫向?qū)Ш讲藛涡Ч?/a>
- jQuery+CSS實現(xiàn)一個側(cè)滑導(dǎo)航菜單代碼
- jquery實現(xiàn)具有收縮功能的垂直導(dǎo)航菜單
- 基于jQuery實現(xiàn)以手風琴方式展開和折疊導(dǎo)航菜單
- jQuery實現(xiàn)二級導(dǎo)航菜單的示例
相關(guān)文章
Jquery遍歷checkbox獲取選中項value值的方法
這篇文章主要介紹了Jquery遍歷checkbox獲取選中項的value值,需要的朋友可以參考下2014-02-02jQuery實現(xiàn)鼠標滑過預(yù)覽圖片大圖效果的方法
這篇文章主要介紹了jQuery實現(xiàn)鼠標滑過預(yù)覽圖片大圖效果的方法,涉及jQuery鼠標事件響應(yīng)及頁面元素屬性動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-04-04jQuery中彈出iframe內(nèi)嵌頁面元素到父頁面并全屏化的實例代碼
這篇文章主要介紹了jQuery中彈出iframe內(nèi)嵌頁面元素到父頁面并全屏化的實例代碼,需要的朋友可以參考下2016-12-12jQuery實現(xiàn)Flash效果上下翻動的中英文導(dǎo)航菜單代碼
這篇文章主要介紹了jQuery實現(xiàn)Flash效果上下翻動的中英文導(dǎo)航菜單代碼,實例分析了jQuery基于鼠標hover事件控制頁面元素動畫效果的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09