From 2da70526eafc30eedb77bb79d047de5fa1e670f0 Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Fri, 16 Jan 2026 20:52:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E5=9B=9E=E5=A4=8D=E6=8C=89=E9=92=AE=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=90=8E=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用原生 document.addEventListener 替代 jQuery 事件委托绑定回复按钮点击事件 - 原生事件监听器在 DOM 解析完成后立即生效,不依赖 jQuery 初始化状态 - 添加 element.closest() 实现事件委托,兼容动态加载的评论 - 保留 jQuery 事件绑定用于 PJAX 相关功能 - 添加 offset() 防护检查避免元素未渲染时报错 --- argontheme.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/argontheme.js b/argontheme.js index a741218..d762e47 100644 --- a/argontheme.js +++ b/argontheme.js @@ -980,16 +980,23 @@ if (argonConfig.waterflow_columns != "1") { }else{ $("#post_comment").addClass("post-comment-force-privatemode-off"); } - $("body,html").animate({ - scrollTop: $('#post_comment').offset().top - 100 - }, 400, 'easeOutCirc'); + + // 滚动到评论框(添加防护检查) + let postComment = $('#post_comment'); + if (postComment.length > 0 && postComment.offset()) { + $("body,html").animate({ + scrollTop: postComment.offset().top - 100 + }, 400, 'easeOutCirc'); + } // 使用 CSS 动画显示回复框 let replyInfo = $('#post_comment_reply_info'); - replyInfo.removeClass('reply-leaving').css('display', 'block'); - // 触发重排以确保动画生效 - replyInfo[0].offsetHeight; - replyInfo.addClass('reply-entering'); + if (replyInfo.length > 0) { + replyInfo.removeClass('reply-leaving').css('display', 'block'); + // 触发重排以确保动画生效 + replyInfo[0].offsetHeight; + replyInfo.addClass('reply-entering'); + } setTimeout(function(){ $("#post_comment_content").focus(); @@ -1010,9 +1017,15 @@ if (argonConfig.waterflow_columns != "1") { $("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off"); } - $(document).on("click" , ".comment-reply" , function(){ - reply(this.getAttribute("data-id")); + // 使用原生事件委托确保第一次点击也能响应 + document.addEventListener('click', function(e) { + let target = e.target.closest('.comment-reply'); + if (target) { + reply(target.getAttribute('data-id')); + } }); + + // 保留 jQuery 事件绑定用于 PJAX 兼容 $(document).on("click pjax:click" , "#post_comment_reply_cancel" , function(){ cancelReply(); }); @@ -3754,7 +3767,8 @@ void 0; } function initRippleEffect() { - var rippleElements = document.querySelectorAll('.btn, .card, .nav-link, .dropdown-item, .page-link, .leftbar-mobile-menu-item > a, .leftbar-mobile-action, .fabtn, .comment-reply, .tag, .badge'); + // 排除大尺寸卡片(文章、评论区、相关文章、页脚等),避免触摸时产生布局问题 + var rippleElements = document.querySelectorAll('.btn, .card:not(article.post):not(#comments):not(#post_comment):not(.related-posts):not(.post-navigation):not(#footer), .nav-link, .dropdown-item, .page-link, .leftbar-mobile-menu-item > a, .leftbar-mobile-action, .fabtn, .comment-reply, .tag, .badge'); rippleElements.forEach(function(el) { if (el.dataset.rippleInit) return; el.dataset.rippleInit = 'true';