feat: 目录弹窗自动滚动到当前章节

This commit is contained in:
李策 2026-03-26 17:57:29 +08:00
parent 1e9c551766
commit 8dd946eac8

View File

@ -575,6 +575,14 @@
html += `<a href="?id=${ch.id}" class="toc-item ${isCurrent}" data-id="${ch.id}">第${ch.id}章:${ch.title}</a>`; html += `<a href="?id=${ch.id}" class="toc-item ${isCurrent}" data-id="${ch.id}">第${ch.id}章:${ch.title}</a>`;
}); });
tocList.innerHTML = html; tocList.innerHTML = html;
// 自动滚动到当前章节
setTimeout(() => {
const currentItem = tocList.querySelector('.current');
if (currentItem) {
currentItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}, 100);
} }
// 更新移动端目录高亮 // 更新移动端目录高亮