From d44d4c2a79c9481648cd41b29d23bdb258700c20 Mon Sep 17 00:00:00 2001 From: elkan1788 Date: Fri, 23 Jun 2023 22:06:42 +0800 Subject: [PATCH] :lipstick: add page comment counter click event. --- assets/css/_common/components/post/post-header.scss | 5 +++++ assets/js/next-boot.js | 8 ++++++++ assets/js/utils.js | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/assets/css/_common/components/post/post-header.scss b/assets/css/_common/components/post/post-header.scss index d899968..b0b76f6 100644 --- a/assets/css/_common/components/post/post-header.scss +++ b/assets/css/_common/components/post/post-header.scss @@ -113,3 +113,8 @@ flex-basis: 100%; height: 0; } + +#comments-count { + cursor: pointer; + border-bottom: 1px solid $link-decoration-color; +} diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index 76354fc..47339f6 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -24,6 +24,14 @@ NexT.boot.registerEvents = function() { // Register comment's components NexT.plugins.register(); + // Register comment counter click event + const commentCnt = document.querySelector('#comments-count'); + if (commentCnt && NexT.CONFIG.page.isPage) { + commentCnt.addEventListener('click', event => { + NexT.utils.slidScrollBarAnime('comments'); + }); + } + // Mobile top menu bar. document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => { event.currentTarget.classList.toggle('toggle-close'); diff --git a/assets/js/utils.js b/assets/js/utils.js index 1b5bcf3..e78675e 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -59,11 +59,13 @@ NexT.utils = { }, slidScrollBarAnime: function (targetId, easing = 'linear', duration = 500) { + const targetObj = document.getElementById(targetId); + window.anime({ targets: document.scrollingElement, duration: duration, easing: easing, - scrollTop: targetId == '' ? 0 : document.getElementById(targetId).getBoundingClientRect().top + window.scrollY + scrollTop: targetId == '' || !targetObj ? 0 : targetObj.getBoundingClientRect().top + window.scrollY }); },