mirror of
https://github.com/afoim/fuwari.git
synced 2026-01-31 09:03:18 +08:00
feat(布局): 添加返回评论区按钮功能
在布局组件中添加返回评论区按钮,当页面滚动超过横幅高度且评论区存在时显示该按钮。点击按钮可平滑滚动至评论区位置。
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user