From 3a16525c27517cd046b383f5fd92d07be6b6d798 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Fri, 29 Aug 2025 15:21:15 +0800 Subject: feat: comment toggle animation --- layouts/_partials/posts/action-menu.html | 6 +- layouts/_partials/posts/comment.html | 117 +++++++++++++------------- layouts/_partials/scripts/action-menu-js.html | 28 ++++-- 3 files changed, 84 insertions(+), 67 deletions(-) diff --git a/layouts/_partials/posts/action-menu.html b/layouts/_partials/posts/action-menu.html index 5f79ad98..63c7ba5c 100644 --- a/layouts/_partials/posts/action-menu.html +++ b/layouts/_partials/posts/action-menu.html @@ -37,8 +37,10 @@ - diff --git a/layouts/_partials/posts/comment.html b/layouts/_partials/posts/comment.html index af0def7e..6e178e5e 100644 --- a/layouts/_partials/posts/comment.html +++ b/layouts/_partials/posts/comment.html @@ -1,66 +1,67 @@ -
- {{ with .Params.comments }} - -
-

{{ T "postPage.staticCommentsSectionHeader" }}

- {{ range . }} -
-
- {{ .name }} - {{ .date }} -
-
- {{ .content | safeHTML }} -
-
- {{ with .source }} -

{{ T "postPage.originallyPostedOn" . }}

- {{ end }} -
+{{ with .Params.comments }} + +
+

{{ T "postPage.staticCommentsSectionHeader" }}

+ {{ range . }} +
+
+ {{ .name }} + {{ .date }}
- {{ end }} -
+
+ {{ .content | safeHTML }} +
+
+ {{ with .source }} +

{{ T "postPage.originallyPostedOn" . }}

+ {{ end }} +
+
{{ end }} +
+{{ end }} + + +

+ *{{ T "emailMe" }} {{ .Site.Params.email }} +

-

- *{{ T "emailMe" }} {{ .Site.Params.email }} + +

+

+ {{ T "postPage.commentNotLoaded" }}

-
-

- {{ T "postPage.commentNotLoaded" }} -

-
+
- - -
+observer.observe(document.getElementById("action-menu")); + diff --git a/layouts/_partials/scripts/action-menu-js.html b/layouts/_partials/scripts/action-menu-js.html index e2db17e7..a0d9391d 100644 --- a/layouts/_partials/scripts/action-menu-js.html +++ b/layouts/_partials/scripts/action-menu-js.html @@ -28,13 +28,27 @@ function initializeComments() { const commentsToggle = document.getElementById('comments-toggle'); const commentsSection = document.getElementById('comments-section'); - if (commentsToggle && commentsSection) { - commentsToggle.addEventListener('click', function() { - const isHidden = commentsSection.style.display === 'none'; - commentsSection.style.display = isHidden ? 'block' : 'none'; - this.style.background = isHidden ? 'rgba(0, 0, 0, 0.1)' : 'transparent'; - }); - } + if (!commentsToggle || !commentsSection) return; + + // click on toggle + commentsToggle.addEventListener('click', function() { + const isHidden = commentsSection.classList.contains('hidden'); + const entranceAnimation = 'animate-slide-in-down'; + const exitAnimation = 'animate-slide-out-up'; + + if (isHidden) { + // swtich on + commentsSection.classList.remove('hidden', exitAnimation); + commentsSection.classList.add(entranceAnimation); + } else { + // switch off + commentsSection.classList.remove(entranceAnimation); + commentsSection.classList.add(exitAnimation); + setTimeout(() => { + commentsSection.classList.add('hidden'); + }, 200); + } + }); } /** -- cgit v1.2.3