From a1bf685c4fb83e05bba3b1e89dd42ea59309cef2 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 19 Jun 2025 13:58:34 +0800 Subject: =?UTF-8?q?fix(like-button):=20=E4=BF=AE=E5=A4=8D=E5=B7=B2?= =?UTF-8?q?=E7=82=B9=E8=B5=9E=E6=8C=89=E9=92=AE=E4=BB=8D=E4=BC=9A=E6=99=83?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免在已点赞状态下添加 near-comments 类,并优化相关样式 Former-commit-id: b61f7a464a405809181fb72109120f62ccc42cd6 --- layouts/partials/components/like-button.html | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/layouts/partials/components/like-button.html b/layouts/partials/components/like-button.html index 02c084b8..aa665453 100644 --- a/layouts/partials/components/like-button.html +++ b/layouts/partials/components/like-button.html @@ -30,6 +30,11 @@ if (shouldHighlight !== isNearComments) { isNearComments = shouldHighlight; + // 如果已经点赞,不添加 near-comments 类(避免晃动) + if (containerEl.classList.contains('liked')) { + return; + } + if (isNearComments) { containerEl.classList.add('near-comments'); } else { @@ -54,6 +59,8 @@ if (localStorage.getItem("liked_" + pageId)) { btnEl.disabled = true; containerEl.classList.add("liked"); + // 移除可能存在的 near-comments 类 + containerEl.classList.remove('near-comments'); updateTooltip(); } }) @@ -65,7 +72,9 @@ window.sendLike = function(pageId) { if (localStorage.getItem("liked_" + pageId)) return; - umami.track('👍 Hit Like Button'); + if (window.location.hostname !== 'localhost') { + umami.track('👍 Hit Like Button'); + } // 添加点击效果 btnEl.classList.add("clicked"); @@ -80,6 +89,8 @@ countEl.innerText = data.likes ?? 1; btnEl.disabled = true; containerEl.classList.add("liked"); + // 移除 near-comments 类,停止晃动 + containerEl.classList.remove('near-comments'); updateTooltip(); }) .catch(() => { @@ -121,6 +132,15 @@ animation: none; } +/* 已点赞状态:保持最高不透明度,不再晃动 */ +.floating-like-container.liked { + opacity: 1 !important; +} + +.floating-like-container.liked.near-comments { + animation: none !important; +} + .floating-like-button { display: flex; flex-direction: column; -- cgit v1.2.3