這次給大家?guī)?active動態(tài)使用實現(xiàn)導(dǎo)航效果,.active動態(tài)使用實現(xiàn)導(dǎo)航效果的注意事項有哪些,下面就是實戰(zhàn)案例,一起來看一下。
通過jq獲取你打開頁面的鏈接 window.location.pathname;
在HTML中給自己的li加入一個ID id的命名與網(wǎng)址鏈接中的href相同
通過jq包含方法找到相對應(yīng)的li給他加入active類名
然后。就沒有然后了。。
jq代碼:
$(function() { varli = $(".title_ul").children("li"); for(vari = 0; i < li.length; i++) { varurl = window.location.pathname; varurl = url.replace("/",""); if(url.indexOf(li[i].id)!=-1) { li[i].firstChild.className ="active"; }else{ li[i].firstChild.className =""; } } })
html代碼:
<body> <p class="title"> <ul class="title_ul"> <li id="index"><a href="index.html"rel="external nofollow"class="">頁面1</a></li> <li id="zf"><a href="zf.html"rel="external nofollow"class="">頁面2</a></li> <li id="gc"><a href="gc.html"rel="external nofollow"class="">頁面3</a></li> <li id="hc"><a href="hc.html"rel="external nofollow"class="">頁面4</a></li> <li id="shwt"><a href="shwt.html"rel="external nofollow"class="">頁面5</a></li> </ul> </p> </body>
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關(guān)注Gxl網(wǎng)其它相關(guān)文章!
推薦閱讀:
jQuery做出鼠標(biāo)滾輪操作圖片縮放大小
jQuery實現(xiàn)回到頂部功能
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com