chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+490
View File
@@ -0,0 +1,490 @@
/* ==========================================================================
YwxApp 文档中心前台样式
三栏布局:左侧目录树 / 中间正文 / 右侧本页锚点
========================================================================== */
:root {
--dc-primary: #2f6fed;
--dc-primary-soft: #eaf1ff;
--dc-text: #24292f;
--dc-text-sub: #656d76;
--dc-border: #e6e8eb;
--dc-bg: #ffffff;
--dc-bg-soft: #f7f8fa;
--dc-code-bg: #f6f8fa;
--dc-header-h: 60px;
--dc-sidebar-w: 268px;
--dc-toc-w: 220px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
margin: 0;
background: var(--dc-bg);
color: var(--dc-text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
"Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
font-size: 15px;
line-height: 1.7;
-webkit-font-smoothing: antialiased;
}
a { color: var(--dc-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
/* ---------------------------- 顶部导航 ---------------------------- */
.dc-header {
position: sticky;
top: 0;
z-index: 100;
height: var(--dc-header-h);
background: rgba(255, 255, 255, .92);
backdrop-filter: saturate(180%) blur(8px);
border-bottom: 1px solid var(--dc-border);
}
.dc-header-inner {
max-width: 1440px;
height: 100%;
margin: 0 auto;
padding: 0 24px;
display: flex;
align-items: center;
gap: 24px;
}
.dc-logo { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.dc-logo:hover { text-decoration: none; }
.dc-logo-mark {
width: 30px; height: 30px;
border-radius: 7px;
background: linear-gradient(135deg, #2f6fed, #6c47ff);
color: #fff;
font-weight: 700;
display: flex; align-items: center; justify-content: center;
}
.dc-logo-text { font-size: 16px; font-weight: 600; color: var(--dc-text); }
.dc-nav { display: flex; align-items: center; gap: 20px; flex: 1; overflow: hidden; }
.dc-nav a { color: var(--dc-text-sub); font-size: 14px; white-space: nowrap; }
.dc-nav a:hover { color: var(--dc-primary); text-decoration: none; }
.dc-search { position: relative; flex-shrink: 0; }
.dc-search input {
width: 210px; height: 34px;
padding: 0 34px 0 12px;
border: 1px solid var(--dc-border);
border-radius: 17px;
background: var(--dc-bg-soft);
font-size: 13px;
outline: none;
transition: all .2s;
}
.dc-search input:focus {
width: 250px;
border-color: var(--dc-primary);
background: #fff;
}
.dc-search button {
position: absolute; right: 4px; top: 3px;
width: 28px; height: 28px;
border: none; background: none;
color: var(--dc-text-sub);
cursor: pointer;
display: flex; align-items: center; justify-content: center;
}
.dc-menu-toggle {
display: none;
width: 34px; height: 34px;
border: 1px solid var(--dc-border);
border-radius: 6px;
background: #fff;
cursor: pointer;
flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.dc-menu-toggle span { display: block; width: 16px; height: 2px; background: var(--dc-text); }
/* ---------------------------- 三栏骨架 ---------------------------- */
.dc-layout {
max-width: 1440px;
margin: 0 auto;
padding: 0 24px;
display: grid;
grid-template-columns: var(--dc-sidebar-w) minmax(0, 1fr) var(--dc-toc-w);
gap: 36px;
align-items: start;
}
/* ---------------------------- 左侧目录 ---------------------------- */
.dc-sidebar {
position: sticky;
top: var(--dc-header-h);
max-height: calc(100vh - var(--dc-header-h));
overflow-y: auto;
padding: 22px 8px 40px 0;
border-right: 1px solid var(--dc-border);
}
.dc-sidebar::-webkit-scrollbar { width: 6px; }
.dc-sidebar::-webkit-scrollbar-thumb { background: #d8dce1; border-radius: 3px; }
.dc-sidebar-head { padding: 0 10px 14px; border-bottom: 1px solid var(--dc-border); margin-bottom: 12px; }
.dc-project-title { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.dc-version-select {
width: 100%; height: 30px;
padding: 0 8px;
border: 1px solid var(--dc-border);
border-radius: 6px;
background: var(--dc-bg-soft);
font-size: 13px;
outline: none;
cursor: pointer;
}
.dc-tree ul { list-style: none; margin: 0; padding: 0; }
.dc-tree > ul > li > .dc-tree-item > .dc-tree-link { font-weight: 600; color: var(--dc-text); }
.dc-tree ul ul { padding-left: 14px; display: none; }
.dc-tree li.is-open > ul { display: block; }
.dc-tree-item {
display: flex; align-items: center;
border-radius: 6px;
margin: 1px 0;
transition: background .15s;
}
.dc-tree-item:hover { background: var(--dc-bg-soft); }
.dc-tree-item.is-active { background: var(--dc-primary-soft); }
.dc-tree-item.is-active > .dc-tree-link { color: var(--dc-primary); font-weight: 600; }
.dc-tree-toggle {
width: 18px; height: 28px;
flex-shrink: 0;
cursor: pointer;
position: relative;
}
.dc-tree-toggle::before {
content: '';
position: absolute;
left: 6px; top: 11px;
width: 5px; height: 5px;
border-right: 1.5px solid var(--dc-text-sub);
border-bottom: 1.5px solid var(--dc-text-sub);
transform: rotate(-45deg);
transition: transform .18s;
}
li.is-open > .dc-tree-item > .dc-tree-toggle::before { transform: rotate(45deg); }
.dc-tree-link {
flex: 1;
padding: 5px 10px 5px 4px;
font-size: 14px;
color: var(--dc-text-sub);
line-height: 1.5;
word-break: break-word;
}
.dc-tree-link:hover { color: var(--dc-primary); text-decoration: none; }
.dc-tree-link.is-dir { cursor: pointer; color: var(--dc-text); font-weight: 500; }
/* 没有折叠箭头的节点需要补齐缩进,保持文字左对齐 */
.dc-tree-item > .dc-tree-link:first-child { padding-left: 22px; }
/* ---------------------------- 中间正文 ---------------------------- */
.dc-main { min-width: 0; padding: 22px 0 60px; }
.dc-crumbs { font-size: 13px; color: var(--dc-text-sub); margin-bottom: 18px; }
.dc-crumb-sep { margin: 0 7px; color: #c9ced4; }
.dc-crumb-current { color: var(--dc-text); }
.dc-article-title {
font-size: 30px;
line-height: 1.35;
margin: 0 0 12px;
font-weight: 650;
letter-spacing: -.3px;
}
.dc-article-meta { font-size: 13px; color: var(--dc-text-sub); padding-bottom: 18px; border-bottom: 1px solid var(--dc-border); }
.dc-dot { margin: 0 8px; }
/* 正文排版 */
.dc-content { padding-top: 22px; }
.dc-content h2 {
font-size: 22px;
margin: 34px 0 14px;
padding-bottom: 8px;
border-bottom: 1px solid var(--dc-border);
scroll-margin-top: calc(var(--dc-header-h) + 16px);
}
.dc-content h3 {
font-size: 18px;
margin: 26px 0 12px;
scroll-margin-top: calc(var(--dc-header-h) + 16px);
}
.dc-content h4 { font-size: 16px; margin: 20px 0 10px; }
.dc-content p { margin: 0 0 15px; }
.dc-content ul, .dc-content ol { margin: 0 0 15px; padding-left: 26px; }
.dc-content li { margin: 5px 0; }
.dc-content img { max-width: 100%; border-radius: 6px; }
.dc-content blockquote {
margin: 0 0 15px;
padding: 10px 16px;
border-left: 4px solid var(--dc-primary);
background: var(--dc-primary-soft);
border-radius: 0 6px 6px 0;
color: var(--dc-text-sub);
}
.dc-content blockquote p:last-child { margin-bottom: 0; }
.dc-content code {
padding: 2px 6px;
background: var(--dc-code-bg);
border-radius: 4px;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 13px;
color: #d63384;
}
.dc-content pre {
position: relative;
margin: 0 0 18px;
padding: 16px;
background: #1f2430;
border-radius: 8px;
overflow-x: auto;
}
.dc-content pre code {
padding: 0;
background: none;
color: #e6e6e6;
font-size: 13px;
line-height: 1.65;
}
.dc-copy-btn {
position: absolute;
top: 8px; right: 8px;
padding: 3px 10px;
border: 1px solid rgba(255, 255, 255, .2);
border-radius: 5px;
background: rgba(255, 255, 255, .08);
color: #cfd4dc;
font-size: 12px;
cursor: pointer;
opacity: 0;
transition: opacity .18s;
}
.dc-content pre:hover .dc-copy-btn { opacity: 1; }
.dc-copy-btn:hover { background: rgba(255, 255, 255, .18); color: #fff; }
.dc-copy-btn.is-done { color: #7ee2a8; border-color: rgba(126, 226, 168, .4); }
.dc-content table {
width: 100%;
margin: 0 0 18px;
border-collapse: collapse;
font-size: 14px;
}
.dc-content th, .dc-content td { padding: 9px 12px; border: 1px solid var(--dc-border); text-align: left; }
.dc-content th { background: var(--dc-bg-soft); font-weight: 600; }
.dc-content tr:nth-child(even) td { background: #fbfcfd; }
.dc-content hr { margin: 28px 0; border: none; border-top: 1px solid var(--dc-border); }
/* 上下篇 */
.dc-pager { display: flex; gap: 16px; margin-top: 44px; }
.dc-pager-item {
flex: 1;
padding: 14px 18px;
border: 1px solid var(--dc-border);
border-radius: 8px;
transition: all .18s;
min-height: 66px;
}
a.dc-pager-item:hover { border-color: var(--dc-primary); background: var(--dc-primary-soft); text-decoration: none; }
.dc-pager-item.is-disabled { border: none; background: none; }
.dc-pager-next { text-align: right; }
.dc-pager-label { display: block; font-size: 12px; color: var(--dc-text-sub); margin-bottom: 4px; }
.dc-pager-title { display: block; font-size: 14px; font-weight: 500; color: var(--dc-text); }
/* ---------------------------- 右侧锚点 ---------------------------- */
.dc-toc {
position: sticky;
top: var(--dc-header-h);
max-height: calc(100vh - var(--dc-header-h));
overflow-y: auto;
padding: 30px 0 40px;
}
.dc-toc-title { font-size: 12px; font-weight: 600; color: var(--dc-text-sub); letter-spacing: .5px; text-transform: uppercase; margin-bottom: 10px; }
.dc-toc-list { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--dc-border); }
.dc-toc-list li a {
display: block;
padding: 4px 0 4px 12px;
margin-left: -2px;
border-left: 2px solid transparent;
font-size: 13px;
color: var(--dc-text-sub);
line-height: 1.5;
}
.dc-toc-list li a:hover { color: var(--dc-primary); text-decoration: none; }
.dc-toc-list li a.is-active { color: var(--dc-primary); border-left-color: var(--dc-primary); font-weight: 500; }
.dc-toc-h3 a { padding-left: 24px !important; font-size: 12.5px; }
/* ---------------------------- 首页 ---------------------------- */
.dc-hero {
padding: 66px 24px 54px;
background: linear-gradient(160deg, #f4f7ff 0%, #ffffff 100%);
border-bottom: 1px solid var(--dc-border);
text-align: center;
}
.dc-hero-inner { max-width: 720px; margin: 0 auto; }
.dc-hero h1 { font-size: 36px; margin: 0 0 12px; font-weight: 700; letter-spacing: -.5px; }
.dc-hero p { color: var(--dc-text-sub); margin: 0 0 26px; font-size: 16px; }
.dc-hero-search { display: flex; gap: 10px; max-width: 520px; margin: 0 auto; }
.dc-hero-search input {
flex: 1; height: 44px;
padding: 0 16px;
border: 1px solid var(--dc-border);
border-radius: 8px;
font-size: 15px;
outline: none;
}
.dc-hero-search input:focus { border-color: var(--dc-primary); }
.dc-hero-search button {
height: 44px; padding: 0 26px;
border: none; border-radius: 8px;
background: var(--dc-primary);
color: #fff; font-size: 15px; cursor: pointer;
}
.dc-hero-search button:hover { background: #2560d8; }
.dc-projects { max-width: 1200px; margin: 0 auto; padding: 44px 24px 60px; }
.dc-project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 20px; }
.dc-project-card {
padding: 22px;
border: 1px solid var(--dc-border);
border-radius: 10px;
background: #fff;
transition: all .2s;
display: flex; flex-direction: column;
}
.dc-project-card:hover { border-color: var(--dc-primary); box-shadow: 0 6px 20px rgba(47, 111, 237, .1); transform: translateY(-2px); }
.dc-project-head { display: flex; gap: 14px; margin-bottom: 14px; }
.dc-project-icon {
width: 46px; height: 46px; flex-shrink: 0;
border-radius: 10px;
background: linear-gradient(135deg, #2f6fed, #6c47ff);
color: #fff;
font-size: 20px; font-weight: 700;
display: flex; align-items: center; justify-content: center;
overflow: hidden;
}
.dc-project-icon img { width: 100%; height: 100%; object-fit: cover; }
.dc-project-info h2 { font-size: 17px; margin: 0 0 5px; }
.dc-project-info h2 a { color: var(--dc-text); }
.dc-project-info p { margin: 0; font-size: 13px; color: var(--dc-text-sub); line-height: 1.6; }
.dc-project-meta { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--dc-text-sub); margin-bottom: 14px; }
.dc-tag { padding: 2px 8px; background: var(--dc-bg-soft); border-radius: 4px; }
.dc-project-recent { list-style: none; margin: 0 0 16px; padding: 12px 0 0; border-top: 1px dashed var(--dc-border); flex: 1; }
.dc-project-recent li { margin: 6px 0; font-size: 13px; }
.dc-project-recent li a { color: var(--dc-text-sub); }
.dc-project-recent li a::before { content: ''; margin-right: 6px; color: #c9ced4; }
.dc-project-recent li a:hover { color: var(--dc-primary); text-decoration: none; }
.dc-project-enter { font-size: 13.5px; font-weight: 500; }
/* ---------------------------- 搜索页 ---------------------------- */
.dc-search-page { max-width: 820px; margin: 0 auto; padding: 40px 24px 60px; }
.dc-search-form { display: flex; gap: 10px; margin-bottom: 26px; }
.dc-search-form input { flex: 1; height: 42px; padding: 0 14px; border: 1px solid var(--dc-border); border-radius: 8px; font-size: 15px; outline: none; }
.dc-search-form input:focus { border-color: var(--dc-primary); }
.dc-search-form select { height: 42px; padding: 0 10px; border: 1px solid var(--dc-border); border-radius: 8px; background: #fff; outline: none; cursor: pointer; }
.dc-search-form button { height: 42px; padding: 0 24px; border: none; border-radius: 8px; background: var(--dc-primary); color: #fff; font-size: 15px; cursor: pointer; }
.dc-search-summary { font-size: 14px; color: var(--dc-text-sub); padding-bottom: 14px; border-bottom: 1px solid var(--dc-border); }
.dc-search-list { list-style: none; margin: 0; padding: 0; }
.dc-search-list li { padding: 18px 0; border-bottom: 1px solid var(--dc-border); }
.dc-search-title { font-size: 17px; font-weight: 600; }
.dc-search-path { font-size: 12px; color: var(--dc-text-sub); margin: 5px 0 7px; }
.dc-search-snippet { margin: 0; font-size: 14px; color: var(--dc-text-sub); line-height: 1.7; }
.dc-search-snippet mark { background: #fff3bf; color: inherit; padding: 0 2px; border-radius: 2px; }
/* ---------------------------- 空态与 404 ---------------------------- */
.dc-empty { padding: 70px 20px; text-align: center; color: var(--dc-text-sub); }
.dc-empty p { margin: 6px 0; }
.dc-empty-tip { font-size: 13px; color: #9aa1a9; }
.dc-notfound { max-width: 560px; margin: 0 auto; padding: 90px 24px; text-align: center; }
.dc-notfound-code { font-size: 84px; font-weight: 800; color: var(--dc-primary-soft); line-height: 1; }
.dc-notfound h1 { font-size: 21px; margin: 12px 0 8px; }
.dc-notfound p { color: var(--dc-text-sub); margin: 0 0 26px; }
.dc-notfound-ops { display: flex; gap: 12px; justify-content: center; }
.dc-btn { display: inline-block; padding: 9px 22px; border: 1px solid var(--dc-border); border-radius: 7px; color: var(--dc-text); font-size: 14px; }
.dc-btn:hover { text-decoration: none; border-color: var(--dc-primary); color: var(--dc-primary); }
.dc-btn-primary { background: var(--dc-primary); border-color: var(--dc-primary); color: #fff; }
.dc-btn-primary:hover { background: #2560d8; color: #fff; }
/* ---------------------------- 页脚 ---------------------------- */
.dc-footer { padding: 26px 24px; border-top: 1px solid var(--dc-border); text-align: center; color: var(--dc-text-sub); font-size: 13px; }
.dc-footer p { margin: 0; }
/* ---------------------------- 遮罩 ---------------------------- */
.dc-mask {
display: none;
position: fixed; inset: 0;
background: rgba(0, 0, 0, .4);
z-index: 98;
}
.dc-mask.is-show { display: block; }
/* ---------------------------- 响应式 ---------------------------- */
@media (max-width: 1180px) {
.dc-layout { grid-template-columns: var(--dc-sidebar-w) minmax(0, 1fr); }
.dc-toc { display: none; }
}
@media (max-width: 860px) {
.dc-nav { display: none; }
.dc-menu-toggle { display: flex; }
.dc-search input { width: 140px; }
.dc-search input:focus { width: 170px; }
.dc-layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px; }
.dc-sidebar {
position: fixed;
top: var(--dc-header-h);
left: 0;
z-index: 99;
width: 280px;
height: calc(100vh - var(--dc-header-h));
max-height: none;
padding: 18px 14px 40px;
background: #fff;
border-right: 1px solid var(--dc-border);
transform: translateX(-100%);
transition: transform .25s;
}
.dc-sidebar.is-open { transform: translateX(0); }
.dc-article-title { font-size: 24px; }
.dc-pager { flex-direction: column; }
.dc-hero h1 { font-size: 27px; }
.dc-project-grid { grid-template-columns: 1fr; }
.dc-search-form { flex-wrap: wrap; }
.dc-search-form input { flex: 1 1 100%; }
}
+266
View File
@@ -0,0 +1,266 @@
/**
* YwxApp 文档中心前台脚本
*
* 提供:目录折叠、移动端抽屉、代码复制、右侧锚点滚动高亮、版本切换。
* 纯原生实现,不依赖任何库。
*/
(function () {
'use strict';
document.addEventListener('DOMContentLoaded', function () {
initTreeToggle();
initMobileDrawer();
initCodeCopy();
initTocScrollSpy();
initVersionSwitch();
scrollActiveIntoView();
});
/**
* 侧边目录展开与折叠
*/
function initTreeToggle() {
var tree = document.querySelector('.dc-tree');
if (!tree) {
return;
}
tree.addEventListener('click', function (e) {
var toggle = e.target.closest('.dc-tree-toggle');
var dirLink = e.target.closest('.dc-tree-link.is-dir');
var trigger = toggle || dirLink;
if (!trigger) {
return;
}
var li = trigger.closest('li');
if (li) {
li.classList.toggle('is-open');
}
});
}
/**
* 移动端侧边栏抽屉
*/
function initMobileDrawer() {
var btn = document.getElementById('dcMenuToggle');
var sidebar = document.getElementById('dcSidebar');
var mask = document.getElementById('dcMask');
if (!btn || !sidebar) {
return;
}
function close() {
sidebar.classList.remove('is-open');
if (mask) {
mask.classList.remove('is-show');
}
}
btn.addEventListener('click', function () {
sidebar.classList.toggle('is-open');
if (mask) {
mask.classList.toggle('is-show', sidebar.classList.contains('is-open'));
}
});
if (mask) {
mask.addEventListener('click', close);
}
// 点击目录项后自动收起抽屉
sidebar.addEventListener('click', function (e) {
if (e.target.closest('a.dc-tree-link') && window.innerWidth <= 860) {
close();
}
});
window.addEventListener('resize', function () {
if (window.innerWidth > 860) {
close();
}
});
}
/**
* 代码块复制按钮
*/
function initCodeCopy() {
var blocks = document.querySelectorAll('.dc-content pre');
Array.prototype.forEach.call(blocks, function (pre) {
var btn = document.createElement('button');
btn.className = 'dc-copy-btn';
btn.type = 'button';
btn.textContent = '复制';
btn.addEventListener('click', function () {
var code = pre.querySelector('code');
var text = code ? code.innerText : pre.innerText;
copyText(text, function (ok) {
btn.textContent = ok ? '已复制' : '复制失败';
btn.classList.toggle('is-done', ok);
setTimeout(function () {
btn.textContent = '复制';
btn.classList.remove('is-done');
}, 1600);
});
});
pre.appendChild(btn);
});
}
/**
* 复制文本到剪贴板,兼容不支持 Clipboard API 的环境
*
* @param {string} text 待复制文本
* @param {Function} cb 回调,参数为是否成功
*/
function copyText(text, cb) {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(function () {
cb(true);
}).catch(function () {
cb(fallbackCopy(text));
});
return;
}
cb(fallbackCopy(text));
}
/**
* 兜底复制方案
*
* @param {string} text 待复制文本
* @returns {boolean}
*/
function fallbackCopy(text) {
var ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
var ok = false;
try {
ok = document.execCommand('copy');
} catch (err) {
ok = false;
}
document.body.removeChild(ta);
return ok;
}
/**
* 右侧锚点滚动高亮
*/
function initTocScrollSpy() {
var toc = document.getElementById('dcToc');
var content = document.getElementById('dcContent');
if (!toc || !content) {
return;
}
var links = Array.prototype.slice.call(toc.querySelectorAll('a[data-anchor]'));
if (!links.length) {
return;
}
var headings = links.map(function (link) {
return document.getElementById(link.getAttribute('data-anchor'));
}).filter(Boolean);
if (!headings.length) {
return;
}
var offset = 90;
var ticking = false;
function update() {
var current = 0;
for (var i = 0; i < headings.length; i++) {
if (headings[i].getBoundingClientRect().top <= offset) {
current = i;
} else {
break;
}
}
links.forEach(function (link, index) {
link.classList.toggle('is-active', index === current);
});
ticking = false;
}
window.addEventListener('scroll', function () {
if (!ticking) {
window.requestAnimationFrame(update);
ticking = true;
}
}, { passive: true });
update();
}
/**
* 版本切换:保持当前文档路径,仅替换版本段
*/
function initVersionSwitch() {
var select = document.getElementById('dcVersionSelect');
if (!select) {
return;
}
select.addEventListener('change', function () {
var opt = select.options[select.selectedIndex];
var isDefault = opt.getAttribute('data-default') === '1';
// 地址形如 /docs/<项目>[/<版本>]/<文档>
var parts = window.location.pathname.split('/').filter(Boolean);
if (parts.length < 2) {
return;
}
var project = parts[1];
var docName = parts[parts.length - 1];
// 只有项目段时说明还未进入具体文档
if (parts.length === 2) {
window.location.href = '/docs/' + project;
return;
}
window.location.href = isDefault
? '/docs/' + project + '/' + docName
: '/docs/' + project + '/' + select.value + '/' + docName;
});
}
/**
* 让当前选中的目录项进入可视区域
*/
function scrollActiveIntoView() {
var active = document.querySelector('.dc-tree-item.is-active');
var sidebar = document.getElementById('dcSidebar');
if (!active || !sidebar) {
return;
}
var top = active.offsetTop - sidebar.clientHeight / 2;
if (top > 0) {
sidebar.scrollTop = top;
}
}
})();