feat(nav.ts): add functionality to set the current link based on the currentMenuItemIndex attribute

This commit is contained in:
Sped0n
2023-10-30 15:55:02 +08:00
parent ead0a84ac7
commit 40f278ce1c

View File

@@ -31,6 +31,24 @@ const indexDispNums = Array.from(
indexDiv.getElementsByClassName('num')
) as HTMLSpanElement[]
// links div
const linksDiv = document.getElementsByClassName('links').item(0) as HTMLDivElement
// links
const links = Array.from(linksDiv.getElementsByClassName('link')) as HTMLAnchorElement[]
// current link index
const currentLinkIndex = document
.getElementById('main')!
.getAttribute('currentMenuItemIndex') as string
// set current link
for (let [index, link] of links.entries()) {
if (index === parseInt(currentLinkIndex)) {
link.classList.add('current')
}
}
/**
* init
*/