jQuery實(shí)現(xiàn)的手風(fēng)琴側(cè)邊菜單效果
本文實(shí)例講述了jQuery實(shí)現(xiàn)的手風(fēng)琴側(cè)邊菜單效果。分享給大家供大家參考,具體如下:
動(dòng)手做了一個(gè)簡(jiǎn)單手風(fēng)琴菜單,上圖:
點(diǎn)擊 B 可收縮 C 列表,點(diǎn)擊 C 改變自身和父節(jié)點(diǎn) B 的樣式,懸浮時(shí)均有不同的樣式改變。
先看頁面代碼,列表的嵌套:
<div id="menuDiv"> <ul id="menu"> <li class="parentLi"> <span>B</span> <ul class="childrenUl"> <li class="childrenLi"><span>C</span></li> <li class="childrenLi"><span>C</span></li> <li class="childrenLi"><span>C</span></li> </ul> </li> <li class="parentLi"> <span>B</span> <ul class="childrenUl"> <li class="childrenLi"><span>C</span></li> <li class="childrenLi"><span>C</span></li> <li class="childrenLi"><span>C</span></li> </ul> </li> <li class="parentLi"> <span>B</span> <ul class="childrenUl"> <li class="childrenLi"><span>C</span></li> <li class="childrenLi"><span>C</span></li> <li class="childrenLi"><span>C</span></li> </ul> </li> </ul> </div>
css 代碼,主要設(shè)置背景色和子菜單左邊框的樣式,設(shè)置懸浮和選中的樣式,開始設(shè)置子菜單不顯示(通過 js 設(shè)置點(diǎn)擊之后再顯示):
#menuDiv{ width: 200px; background-color: #029FD4; } .parentLi { width: 100%; line-height: 40px; margin-top: 1px; background: #1C73BA; color: #fff; cursor: pointer; font-weight:bolder; } .parentLi span { padding: 10px; } .parentLi:hover, .selectedParentMenu { background: #0033CC; } .childrenUl { background-color: #ffffff; display: none; } .childrenLi { width: 100%; line-height: 30px; font-size: .9em; margin-top: 1px; background: #63B8FF; color: #000000; padding-left: 15px; cursor: pointer; } .childrenLi:hover, .selectedChildrenMenu { border-left: 5px #0033CC solid; background: #0099CC; padding-left: 15px; }
接下來就是點(diǎn)擊事件的代碼:
$(".parentLi").click(function(event) { $(this).children('.childrenUl').slideToggle(); }); $(".childrenLi").click(function(event) { event.stopPropagation(); $(".childrenLi").removeClass('selectedChildrenMenu'); $(".parentLi").removeClass('selectedParentMenu'); $(this).parents(".parentLi").addClass('selectedParentMenu'); $(this).addClass('selectedChildrenMenu'); });
需要注意的是列表嵌套,會(huì)導(dǎo)致事件冒泡,所以在子菜單的點(diǎn)擊事件里面要組織冒泡,event.stopPropagation(); 詳見 API
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery插件制作 手風(fēng)琴Panel效果實(shí)現(xiàn)
- 基于jquery的slideDown和slideUp做手風(fēng)琴
- jQuery制作效果超棒的手風(fēng)琴折疊菜單
- jquery手風(fēng)琴特效插件
- jquery實(shí)現(xiàn)手風(fēng)琴效果實(shí)例代碼
- 精心挑選的12款優(yōu)秀的基于jQuery的手風(fēng)琴效果插件和教程
- 基于Jquery代碼實(shí)現(xiàn)手風(fēng)琴菜單
- jQuery實(shí)現(xiàn)氣球彈出框式的側(cè)邊導(dǎo)航菜單效果
- 基于jQuery傾斜打開側(cè)邊欄菜單特效代碼
- jQuery 實(shí)現(xiàn)側(cè)邊浮動(dòng)導(dǎo)航菜單效果
相關(guān)文章
jQuery Easy UI中根據(jù)第一個(gè)下拉框選中的值設(shè)置第二個(gè)下拉框是否可以編輯
這篇文章主要介紹了jQuery Easy UI中根據(jù)第一個(gè)下拉框選中的值設(shè)置第二個(gè)下拉框是否可以編輯的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11Bookmarklet實(shí)現(xiàn)啟動(dòng)jQuery(模仿 云輸入法)
最近流行的 sogo云輸入法, QQ云輸入法,都用到了bookmarklet技術(shù)。2010-09-09jQuery常用知識(shí)點(diǎn)總結(jié)以及平時(shí)封裝常用函數(shù)
這篇文章主要介紹了jQuery常用知識(shí)點(diǎn)總結(jié)以及平時(shí)封裝常用函數(shù) 的相關(guān)資料,需要的朋友可以參考下2016-02-02Jquery 垂直多級(jí)手風(fēng)琴菜單附源碼下載
本文給大家分享一款簡(jiǎn)單但實(shí)用的多級(jí)垂直手風(fēng)琴下拉菜單列表,完全使用css來制作多級(jí)手風(fēng)琴菜單,通過該代碼將不同的子菜單進(jìn)行分組制作出多級(jí)菜單的效果,本文附效果演示和源碼下載感興趣的朋友一起學(xué)習(xí)吧2015-11-11jquery Ajax 實(shí)現(xiàn)加載數(shù)據(jù)前動(dòng)畫效果的示例代碼
本篇文章主要是對(duì)jquery Ajax實(shí)現(xiàn)加載數(shù)據(jù)前動(dòng)畫效果的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-02-02jQuery獲取父元素節(jié)點(diǎn)、子元素節(jié)點(diǎn)及兄弟元素節(jié)點(diǎn)的方法
這篇文章主要介紹了jQuery獲取父元素節(jié)點(diǎn)、子元素節(jié)點(diǎn)及兄弟元素節(jié)點(diǎn)的方法,結(jié)合實(shí)例形式總結(jié)分析了jQuery節(jié)點(diǎn)操作的相關(guān)技巧,需要的朋友可以參考下2016-04-04