本文實(shí)例講述了jQuery實(shí)現(xiàn)的手風(fēng)琴側(cè)邊菜單效果。分享給大家供大家參考,具體如下:
創(chuàng)新互聯(lián)建站主要從事做網(wǎng)站、成都網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)平南,10年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):18980820575
動(dòng)手做了一個(gè)簡(jiǎn)單手風(fēng)琴菜單,上圖:
點(diǎn)擊 B 可收縮 C 列表,點(diǎn)擊 C 改變自身和父節(jié)點(diǎn) B 的樣式,懸浮時(shí)均有不同的樣式改變。
先看頁(yè)面代碼,列表的嵌套:
<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è)置懸浮和選中的樣式,開(kāi)始設(shè)置子菜單不顯示(通過(guò) 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; }
接下來(lái)就是點(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(); 詳見(jiàn) API
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫(huà)與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
當(dāng)前名稱(chēng):jQuery實(shí)現(xiàn)的手風(fēng)琴側(cè)邊菜單效果
URL地址:http://chinadenli.net/article16/jsigdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、關(guān)鍵詞優(yōu)化、網(wǎng)站排名、用戶(hù)體驗(yàn)、域名注冊(cè)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)