feat: 新增'分类展开/收起'按钮
This commit is contained in:
@@ -626,6 +626,42 @@ body .content.expanded {
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
/* 分类切换按钮 */
|
||||
.category-toggle {
|
||||
position: fixed;
|
||||
bottom: 5rem;
|
||||
right: 2rem;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(145deg, var(--site-card-bg-gradient-1), var(--site-card-bg-gradient-2));
|
||||
color: var(--text-bright);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
z-index: 100;
|
||||
box-shadow: 0 4px 16px var(--shadow-color);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.category-toggle:hover {
|
||||
transform: translateY(-2px);
|
||||
background: linear-gradient(145deg, var(--secondary-bg), var(--site-card-bg-gradient-1));
|
||||
box-shadow: 0 6px 20px var(--shadow-color);
|
||||
color: var(--accent-color);
|
||||
}
|
||||
|
||||
.category-toggle:active {
|
||||
transform: translateY(0);
|
||||
box-shadow: 0 2px 8px var(--shadow-color);
|
||||
}
|
||||
|
||||
.category-toggle i {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
/* 搜索框 */
|
||||
.search-box {
|
||||
position: relative;
|
||||
@@ -1730,6 +1766,12 @@ body .content.expanded {
|
||||
animation: glow 3s ease-in-out infinite alternate;
|
||||
}
|
||||
|
||||
/* 移动端分类切换按钮 */
|
||||
.category-toggle {
|
||||
bottom: 4rem;
|
||||
right: 1rem;
|
||||
}
|
||||
|
||||
/* 分类样式优化 */
|
||||
.category {
|
||||
margin: 0 0.15rem 1.5rem 0.15rem;
|
||||
@@ -1792,6 +1834,7 @@ body .content.expanded {
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
|
||||
.welcome-section {
|
||||
padding: 0 1rem;
|
||||
margin-bottom: 2rem;
|
||||
|
||||
@@ -344,19 +344,60 @@ window.MeNav = {
|
||||
|
||||
// 多层级嵌套书签功能
|
||||
window.MeNav.expandAll = function() {
|
||||
document.querySelectorAll('.category.collapsed, .group.collapsed').forEach(element => {
|
||||
element.classList.remove('collapsed');
|
||||
saveToggleState(element, 'expanded');
|
||||
});
|
||||
const activePage = document.querySelector('.page.active');
|
||||
if (activePage) {
|
||||
activePage.querySelectorAll('.category.collapsed, .group.collapsed').forEach(element => {
|
||||
element.classList.remove('collapsed');
|
||||
saveToggleState(element, 'expanded');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
window.MeNav.collapseAll = function() {
|
||||
document.querySelectorAll('.category:not(.collapsed), .group:not(.collapsed)').forEach(element => {
|
||||
element.classList.add('collapsed');
|
||||
saveToggleState(element, 'collapsed');
|
||||
});
|
||||
const activePage = document.querySelector('.page.active');
|
||||
if (activePage) {
|
||||
activePage.querySelectorAll('.category:not(.collapsed), .group:not(.collapsed)').forEach(element => {
|
||||
element.classList.add('collapsed');
|
||||
saveToggleState(element, 'collapsed');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 智能切换分类展开/收起状态
|
||||
window.MeNav.toggleCategories = function() {
|
||||
const activePage = document.querySelector('.page.active');
|
||||
if (!activePage) return;
|
||||
|
||||
const allElements = activePage.querySelectorAll('.category, .group');
|
||||
const collapsedElements = activePage.querySelectorAll('.category.collapsed, .group.collapsed');
|
||||
|
||||
// 如果收起的数量 >= 总数的一半,执行展开;否则执行收起
|
||||
if (collapsedElements.length >= allElements.length / 2) {
|
||||
window.MeNav.expandAll();
|
||||
updateCategoryToggleIcon('up');
|
||||
} else {
|
||||
window.MeNav.collapseAll();
|
||||
updateCategoryToggleIcon('down');
|
||||
}
|
||||
};
|
||||
|
||||
// 更新分类切换按钮图标
|
||||
function updateCategoryToggleIcon(state) {
|
||||
const toggleBtn = document.getElementById('category-toggle');
|
||||
if (!toggleBtn) return;
|
||||
|
||||
const icon = toggleBtn.querySelector('i');
|
||||
if (!icon) return;
|
||||
|
||||
if (state === 'up') {
|
||||
icon.className = 'fas fa-angle-double-up';
|
||||
toggleBtn.setAttribute('aria-label', '收起分类');
|
||||
} else {
|
||||
icon.className = 'fas fa-angle-double-down';
|
||||
toggleBtn.setAttribute('aria-label', '展开分类');
|
||||
}
|
||||
}
|
||||
|
||||
window.MeNav.toggleCategory = function(categoryName, subcategoryName = null, groupName = null) {
|
||||
const selector = groupName
|
||||
? `[data-name="${categoryName}"] [data-name="${subcategoryName}"] [data-name="${groupName}"]`
|
||||
@@ -1446,6 +1487,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// 初始化嵌套分类功能
|
||||
initializeNestedCategories();
|
||||
|
||||
// 初始化分类切换按钮
|
||||
const categoryToggleBtn = document.getElementById('category-toggle');
|
||||
if (categoryToggleBtn) {
|
||||
categoryToggleBtn.addEventListener('click', function() {
|
||||
window.MeNav.toggleCategories();
|
||||
});
|
||||
} else {
|
||||
console.error('Category toggle button not found');
|
||||
}
|
||||
|
||||
// 初始化搜索索引(使用requestIdleCallback或setTimeout延迟初始化,避免影响页面加载)
|
||||
if ('requestIdleCallback' in window) {
|
||||
requestIdleCallback(() => initSearchIndex());
|
||||
|
||||
@@ -132,6 +132,11 @@
|
||||
{{/each}}
|
||||
</main>
|
||||
|
||||
<!-- 分类切换按钮 -->
|
||||
<button class="category-toggle" id="category-toggle" aria-label="展开/收起分类">
|
||||
<i class="fas fa-angle-double-down"></i>
|
||||
</button>
|
||||
|
||||
<!-- 主题切换按钮 -->
|
||||
<button class="theme-toggle" aria-label="切换主题">
|
||||
<i class="fas fa-moon"></i>
|
||||
|
||||
Reference in New Issue
Block a user