feat(布局): 添加返回评论区按钮功能

在布局组件中添加返回评论区按钮,当页面滚动超过横幅高度且评论区存在时显示该按钮。点击按钮可平滑滚动至评论区位置。
This commit is contained in:
二叉树树
2026-01-09 19:17:59 +08:00
parent 2e98a35105
commit 8a331d199c
2 changed files with 26 additions and 0 deletions

View File

@@ -623,6 +623,7 @@ if (window?.swup?.hooks) {
}
let backToTopBtn = document.getElementById('back-to-top-btn');
let goToCommentsBtn = document.getElementById('go-to-comments-btn');
let toc = document.getElementById('toc-wrapper');
let navbar = document.getElementById('navbar-wrapper')
function scrollFunction() {
@@ -636,6 +637,16 @@ function scrollFunction() {
}
}
if (goToCommentsBtn) {
// Only show if comments exist and scrolled down
const commentsExist = !!document.getElementById('giscus-container');
if (commentsExist && (document.body.scrollTop > bannerHeight || document.documentElement.scrollTop > bannerHeight)) {
goToCommentsBtn.classList.remove('hide')
} else {
goToCommentsBtn.classList.add('hide')
}
}
if (bannerEnabled && toc) {
if (document.body.scrollTop > bannerHeight || document.documentElement.scrollTop > bannerHeight) {
toc.classList.remove('toc-hide')