這次給大家帶來.active動態使用實現導航效果,.active動態使用實現導航效果的注意事項有哪些,下面就是實戰案例,一起來看一下。
通過jq獲取你打開頁面的鏈接 window.location.pathname;
在HTML中給自己的li加入一個ID id的命名與網址鏈接中的href相同
通過jq包含方法找到相對應的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>
相信看了本文案例你已經掌握了方法,更多精彩請關注Gxl網其它相關文章!
推薦閱讀:
jQuery做出鼠標滾輪操作圖片縮放大小
jQuery實現回到頂部功能
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com