1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-16 23:22:20 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

导航栏中突出当前页面项

This commit is contained in:
2022-04-02 19:01:13 +08:00
parent 3cf3e4630e
commit 8635e5dbac
3 changed files with 55 additions and 7 deletions

View File

@@ -7,7 +7,7 @@
</nobr>
</div>
<div class="grid-item exnarrowHide" style="text-align: right; color: white;">
<a class="narrowHide" href="/">首页</a>
<a class="home narrowHide" href="/">首页</a>
<a href="/search">搜索</a>
<a href="/category">分类</a>
<a class="narrowHide" href="/about">关于</a>
@@ -15,4 +15,33 @@
</div>
<div class="grid-item"></div>
</div>
</div>
</div>
<script>
function navbarHighlight() {
// 导航栏中突出当前页面
var route = location.pathname.split('/').filter(s=>!!s);
var page = route[route.length-1];
// 首页
if(route.length === 0) {
$(".home").addClass("active");
return;
}
//其他页面
console.log("page:", page);
$("a").toArray().forEach(element => {
var linkRoute = element.getAttribute("href").split('/').filter(s=>!!s);
console.log(element.href, linkRoute);
if(linkRoute.length > 0) {
var linkPage = linkRoute[linkRoute.length-1];
console.log(element, linkPage);
if(page == linkPage) {
$(element).addClass("active");
return;
}
}
});
}
navbarHighlight();
</script>