feat(scrollbar): 隐藏侧边栏和内容区域滚动条并添加顶部滚动进度条
This commit is contained in:
@@ -402,9 +402,12 @@ body.loaded .layout {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.6rem; /* 从1rem减小到0.6rem */
|
gap: 0.6rem; /* 从1rem减小到0.6rem */
|
||||||
/* 自定义滚动条样式 */
|
/* 隐藏滚动条但保持滚动功能 */
|
||||||
scrollbar-width: thin; /* Firefox */
|
scrollbar-width: none; /* Firefox */
|
||||||
scrollbar-color: var(--scrollbar-color) transparent; /* Firefox */
|
}
|
||||||
|
|
||||||
|
.sidebar-content::-webkit-scrollbar {
|
||||||
|
display: none; /* Webkit browsers */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 折叠状态下的内容区域调整 */
|
/* 折叠状态下的内容区域调整 */
|
||||||
@@ -577,35 +580,21 @@ body.loaded .layout {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
/* 应用自定义滚动条样式 */
|
/* 隐藏滚动条但保持滚动功能 */
|
||||||
scrollbar-width: thin; /* Firefox */
|
scrollbar-width: none; /* Firefox */
|
||||||
scrollbar-color: var(--scrollbar-color) transparent; /* Firefox */
|
|
||||||
transition: background-color 0.3s ease, margin-left 0.3s ease, max-width 0.3s ease;
|
transition: background-color 0.3s ease, margin-left 0.3s ease, max-width 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content::-webkit-scrollbar {
|
||||||
|
display: none; /* Webkit browsers */
|
||||||
|
}
|
||||||
|
|
||||||
/* 优化内容区域在侧边栏折叠状态下的边距 */
|
/* 优化内容区域在侧边栏折叠状态下的边距 */
|
||||||
body .content.expanded {
|
body .content.expanded {
|
||||||
margin-left: var(--sidebar-collapsed-width);
|
margin-left: var(--sidebar-collapsed-width);
|
||||||
max-width: calc(100vw - var(--sidebar-collapsed-width));
|
max-width: calc(100vw - var(--sidebar-collapsed-width));
|
||||||
}
|
}
|
||||||
|
|
||||||
.content::-webkit-scrollbar {
|
|
||||||
width: 7px; /* 统一滚动条宽度 */
|
|
||||||
}
|
|
||||||
|
|
||||||
.content::-webkit-scrollbar-track {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content::-webkit-scrollbar-thumb {
|
|
||||||
background-color: var(--scrollbar-color);
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content::-webkit-scrollbar-thumb:hover {
|
|
||||||
background-color: var(--scrollbar-hover-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 搜索框容器 - 固定在顶部 */
|
/* 搜索框容器 - 固定在顶部 */
|
||||||
.search-container {
|
.search-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -1274,6 +1263,11 @@ body .content.expanded {
|
|||||||
bottom: 1rem;
|
bottom: 1rem;
|
||||||
right: 1rem;
|
right: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 移动端滚动进度条调整 */
|
||||||
|
.scroll-progress {
|
||||||
|
height: 4px; /* 移动端略粗一些 */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
@@ -1586,4 +1580,16 @@ body .content.expanded {
|
|||||||
.sidebar.active .submenu-item {
|
.sidebar.active .submenu-item {
|
||||||
padding: 0.5rem 0.6rem;
|
padding: 0.5rem 0.6rem;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 滚动进度指示条 */
|
||||||
|
.scroll-progress {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 3px;
|
||||||
|
width: 0;
|
||||||
|
background-color: var(--accent-color);
|
||||||
|
z-index: 1000;
|
||||||
|
transition: width 0.1s ease-out;
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const themeToggle = document.querySelector('.theme-toggle');
|
const themeToggle = document.querySelector('.theme-toggle');
|
||||||
const themeIcon = themeToggle.querySelector('i');
|
const themeIcon = themeToggle.querySelector('i');
|
||||||
|
|
||||||
|
// 滚动进度条元素
|
||||||
|
const scrollProgress = document.querySelector('.scroll-progress');
|
||||||
|
|
||||||
// 移除预加载类,允许CSS过渡效果
|
// 移除预加载类,允许CSS过渡效果
|
||||||
document.documentElement.classList.remove('preload');
|
document.documentElement.classList.remove('preload');
|
||||||
|
|
||||||
@@ -233,8 +236,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
sidebar.classList.remove('collapsed');
|
sidebar.classList.remove('collapsed');
|
||||||
content.classList.remove('expanded');
|
content.classList.remove('expanded');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重新计算滚动进度
|
||||||
|
updateScrollProgress();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 更新滚动进度条
|
||||||
|
function updateScrollProgress() {
|
||||||
|
const scrollTop = content.scrollTop || 0;
|
||||||
|
const scrollHeight = content.scrollHeight - content.clientHeight || 1;
|
||||||
|
const scrollPercent = (scrollTop / scrollHeight) * 100;
|
||||||
|
scrollProgress.style.width = scrollPercent + '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听内容区域的滚动事件
|
||||||
|
content.addEventListener('scroll', updateScrollProgress);
|
||||||
|
|
||||||
|
// 初始化时更新一次滚动进度
|
||||||
|
updateScrollProgress();
|
||||||
|
|
||||||
// 页面切换功能
|
// 页面切换功能
|
||||||
function showPage(pageId, skipSearchReset = false) {
|
function showPage(pageId, skipSearchReset = false) {
|
||||||
if (currentPageId === pageId && !skipSearchReset && !isInitialLoad) return;
|
if (currentPageId === pageId && !skipSearchReset && !isInitialLoad) return;
|
||||||
@@ -261,6 +281,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 重置滚动位置并更新进度条
|
||||||
|
content.scrollTop = 0;
|
||||||
|
updateScrollProgress();
|
||||||
|
|
||||||
// 只有在非搜索状态下才重置搜索
|
// 只有在非搜索状态下才重置搜索
|
||||||
if (!skipSearchReset) {
|
if (!skipSearchReset) {
|
||||||
searchInput.value = '';
|
searchInput.value = '';
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||||
</head>
|
</head>
|
||||||
<body class="loading">
|
<body class="loading">
|
||||||
|
<!-- 滚动进度指示条 -->
|
||||||
|
<div class="scroll-progress"></div>
|
||||||
<div class="layout">
|
<div class="layout">
|
||||||
<!-- 移动端按钮 -->
|
<!-- 移动端按钮 -->
|
||||||
<div class="mobile-buttons">
|
<div class="mobile-buttons">
|
||||||
@@ -71,8 +73,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="copyright">
|
<div class="copyright">
|
||||||
<p>© {{CURRENT_YEAR}} <a href="https://github.com/rbetree/menav" target="_blank">MeNav</a></p>
|
<p>© {{CURRENT_YEAR}} <a href="https://github.com/rbetree/menav" target="_blank" rel="noopener">MeNav</a></p>
|
||||||
<p>by <a href="https://github.com/rbetree" target="_blank">rbetree</a></p>
|
<p>by <a href="https://github.com/rbetree" target="_blank" rel="noopener">rbetree</a></p>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user