From f7c587c03e224f366cb772a41136d4e530300880 Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Thu, 22 Jan 2026 16:31:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E7=AB=AF=E6=96=87=E7=AB=A0=E7=9B=AE=E5=BD=95=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加独立的 window scroll 事件监听,确保滚动时触发更新 - 获取 headIndex 实例并手动调用 updateCurrent 方法 - 添加 PJAX 完成后的目录更新逻辑 - 使用节流优化滚动性能(100ms 延迟) --- sidebar.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sidebar.php b/sidebar.php index dbdfe4a..90ce01c 100644 --- a/sidebar.php +++ b/sidebar.php @@ -524,6 +524,7 @@ $author_desc = get_option('argon_sidebar_author_description'); // 检查 jQuery 和 headIndex 是否都已加载 if (typeof jQuery !== 'undefined' && typeof jQuery.fn.headIndex === 'function') { jQuery(document).ready(function($) { + // 初始化 headIndex $(document).headIndex({ articleWrapSelector: '#post_content', indexBoxSelector: '#leftbar_catalog', @@ -536,6 +537,31 @@ $author_desc = get_option('argon_sidebar_author_description'); offset: 80, defaultExpanded: true }); + + // 获取 headIndex 实例 + var headIndexInstance = $(document).data('headIndex'); + + // 添加额外的滚动监听,确保目录跟随 + var scrollTimer = null; + $(window).on('scroll.desktopCatalog', function() { + if (scrollTimer) { + clearTimeout(scrollTimer); + } + scrollTimer = setTimeout(function() { + if (headIndexInstance && typeof headIndexInstance.updateCurrent === 'function') { + headIndexInstance.updateCurrent(); + } + }, 100); + }); + + // PJAX 后重新绑定 + $(document).on('pjax:complete', function() { + if (headIndexInstance && typeof headIndexInstance.updateCurrent === 'function') { + setTimeout(function() { + headIndexInstance.updateCurrent(); + }, 300); + } + }); }); } else { // 如果还没加载完成,等待后重试