jQuery實(shí)現(xiàn)簡潔的導(dǎo)航菜單效果
本文實(shí)例講述了JavaScript實(shí)現(xiàn)的伸展收縮型菜單代碼。分享給大家供大家參考。具體如下:
運(yùn)行效果截圖如下:
鼠標(biāo)懸浮時菜單項向上移動成藍(lán)底白字,點(diǎn)擊之后底部會有藍(lán)條表示當(dāng)前選中項。
頁面代碼,菜單的每一項都是一個 div ,其中包括一個 ul 用來放置顯示文字等,另一個 div 則是底部的藍(lán)條,需要給第一項和最后一項設(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 的高度,鼠標(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'); }); })
以上就是jQuery實(shí)現(xiàn)簡潔的導(dǎo)航菜單效果的關(guān)鍵代碼,希望對大家的學(xué)習(xí)有所幫助。
- JQuery 寫的個性導(dǎo)航菜單
- 基于jquery實(shí)現(xiàn)導(dǎo)航菜單高亮顯示(兩種方法)
- jQuery彈性滑動導(dǎo)航菜單實(shí)現(xiàn)思路及代碼
- Jquery實(shí)現(xiàn)帶動畫效果的經(jīng)典二級導(dǎo)航菜單
- 基于jQuery的簡單的列表導(dǎo)航菜單
- jQuery實(shí)現(xiàn)的動態(tài)伸縮導(dǎo)航菜單實(shí)例
- 純CSS打造的導(dǎo)航菜單(附j(luò)query版)
- jQuery三級下拉列表導(dǎo)航菜單代碼分享
- Jquery+CSS 創(chuàng)建流動導(dǎo)航菜單 Fluid Navigation
- jQuery漸變發(fā)光導(dǎo)航菜單的實(shí)例代碼
- 分享14個很酷的jQuery導(dǎo)航菜單插件
- jQuery實(shí)現(xiàn)的背景動態(tài)變化導(dǎo)航菜單效果
- 制作jquery遮罩層效果導(dǎo)航菜單代碼分享
- jQuery實(shí)現(xiàn)簡單漂亮的Nav導(dǎo)航菜單效果
相關(guān)文章
jQuery 學(xué)習(xí)第五課 Ajax 使用說明
關(guān)于ajax早已不是新鮮話題,而jQuery使ajax變得無比簡單。2010-05-05jQuery實(shí)現(xiàn)TAB選項卡切換特效簡單演示
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)TAB選項卡切換特效簡單演示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-03-03按Enter鍵觸發(fā)事件的jquery方法實(shí)現(xiàn)代碼
這篇文章主要介紹了按Enter鍵觸發(fā)事件的jquery方法,需要的朋友可以參考下2014-02-02基于jQuery UI CSS Framework開發(fā)Widget的經(jīng)驗
jQuery UI CSS Framework是jQuery UI中的一個樣式框架,可以利用jQuery Theme roller 來生成自己想要的css樣式效果。我們可以利用jQuery UI的一些框架來開發(fā)出基于jQuery UI CSS Framework效果的插件來。2010-08-08jquery實(shí)現(xiàn)背景跟隨鼠標(biāo)滑動導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了jquery背景跟隨鼠標(biāo)滑動導(dǎo)航,特別美觀,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-11-11jQuery實(shí)現(xiàn)購物車計算價格功能的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)購物車計算價格功能的方法,實(shí)例分析了jQuery針對html元素的操作技巧,非常具有實(shí)用價值,需要的朋友可以參考下2015-03-03jQuery實(shí)現(xiàn)動畫效果circle實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)動畫效果circle的方法,涉及jquery鼠標(biāo)事件及頁面動畫操作相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08