mirror of
https://github.com/afoim/fuwari.git
synced 2026-01-31 00:53:19 +08:00
fix #159 (布局): 修复页面滚动控制元素引用刷新问题
在页面切换后,滚动控制相关的DOM元素引用未及时更新,导致滚动功能失效。添加refreshControlRefs函数在每次滚动检查前刷新引用,并确保页面加载完成后立即执行一次滚动检查。
This commit is contained in:
@@ -503,6 +503,7 @@ const setup = () => {
|
||||
if (heightExtend) {
|
||||
heightExtend.classList.remove('hidden')
|
||||
}
|
||||
scrollFunction()
|
||||
});
|
||||
window.swup.hooks.on('visit:end', (_visit: {to: {url: string}}) => {
|
||||
setTimeout(() => {
|
||||
@@ -529,7 +530,14 @@ 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 refreshControlRefs() {
|
||||
backToTopBtn = document.getElementById('back-to-top-btn');
|
||||
goToCommentsBtn = document.getElementById('go-to-comments-btn');
|
||||
toc = document.getElementById('toc-wrapper');
|
||||
navbar = document.getElementById('navbar-wrapper')
|
||||
}
|
||||
function scrollFunction() {
|
||||
refreshControlRefs()
|
||||
let bannerHeight = window.innerHeight * (BANNER_HEIGHT / 100)
|
||||
|
||||
if (backToTopBtn) {
|
||||
@@ -576,6 +584,11 @@ function scrollFunction() {
|
||||
}
|
||||
}
|
||||
window.onscroll = scrollFunction
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', scrollFunction)
|
||||
} else {
|
||||
scrollFunction()
|
||||
}
|
||||
|
||||
window.onresize = () => {
|
||||
// calculate the --banner-height-extend, which needs to be a multiple of 4 to avoid blurry text
|
||||
|
||||
Reference in New Issue
Block a user