custom categoryBar

This commit is contained in:
2025-08-14 16:15:18 +08:00
parent b0a4ee340b
commit 2c9440b16a
8 changed files with 114 additions and 4 deletions

View File

@@ -893,6 +893,27 @@ document.addEventListener('DOMContentLoaded', () => {
tabsFn()
}
/**
* 自己写的,实现功能切换类别表
*/
const setCategoryBarActive = () => {
const categoryBar = document.querySelector("#category-bar");
const currentPath = decodeURIComponent(window.location.pathname);
const isHomePage = currentPath === GLOBAL_CONFIG.root;
if (categoryBar) {
const categoryItems = categoryBar.querySelectorAll(".category-bar-item");
categoryItems.forEach(item => item.classList.remove("select"));
const activeItemId = isHomePage ? "category-bar-home" : currentPath.split("/").slice(-2, -1)[0];
const activeItem = document.getElementById(activeItemId);
if (activeItem) {
activeItem.classList.add("select");
}
}
};
const refreshFn = () => {
initAdjust()
justifiedIndexPostUI()
@@ -905,6 +926,7 @@ document.addEventListener('DOMContentLoaded', () => {
GLOBAL_CONFIG.runtime && addRuntime()
addLastPushDate()
toggleCardCategory()
setCategoryBarActive()
}
GLOBAL_CONFIG_SITE.pageType === 'home' && scrollDownInIndex()