From b211c8258c8e51f23998fde49e3d9ef602b8abd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Fri, 31 May 2024 20:32:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=84=E8=AE=BA=E5=8C=BA=E8=A7=86?= =?UTF-8?q?=E5=8F=A3=E6=87=92=E5=8A=A0=E8=BD=BD=20(#480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 1 + layout/_partial/comments/artalk/script.ejs | 17 ++++---- layout/_partial/comments/beaudar/script.ejs | 43 +++++++++---------- layout/_partial/comments/giscus/script.ejs | 22 +++++----- layout/_partial/comments/twikoo/script.ejs | 32 +++++++------- .../_partial/comments/utterances/script.ejs | 43 +++++++++---------- layout/_partial/comments/waline/script.ejs | 21 ++++----- source/js/main.js | 14 ++++++ 8 files changed, 98 insertions(+), 95 deletions(-) diff --git a/_config.yml b/_config.yml index 349c4cd0e..db1d99ffe 100755 --- a/_config.yml +++ b/_config.yml @@ -207,6 +207,7 @@ search: comments: service: # beaudar, utterances, giscus, twikoo, waline, artalk comment_title: 快来参与讨论吧~ + lazyload: false # true / false # beaudar # https://beaudar.lipk.org/ beaudar: diff --git a/layout/_partial/comments/artalk/script.ejs b/layout/_partial/comments/artalk/script.ejs index 14d33c31e..74e70fc3b 100644 --- a/layout/_partial/comments/artalk/script.ejs +++ b/layout/_partial/comments/artalk/script.ejs @@ -1,14 +1,16 @@ - \ No newline at end of file diff --git a/layout/_partial/comments/beaudar/script.ejs b/layout/_partial/comments/beaudar/script.ejs index 53a7ceb42..2ca7f0373 100644 --- a/layout/_partial/comments/beaudar/script.ejs +++ b/layout/_partial/comments/beaudar/script.ejs @@ -1,26 +1,23 @@ - diff --git a/layout/_partial/comments/giscus/script.ejs b/layout/_partial/comments/giscus/script.ejs index b07342bc2..0788c1841 100644 --- a/layout/_partial/comments/giscus/script.ejs +++ b/layout/_partial/comments/giscus/script.ejs @@ -1,22 +1,22 @@ - diff --git a/layout/_partial/comments/twikoo/script.ejs b/layout/_partial/comments/twikoo/script.ejs index a905f4108..ed52fb06d 100644 --- a/layout/_partial/comments/twikoo/script.ejs +++ b/layout/_partial/comments/twikoo/script.ejs @@ -1,20 +1,18 @@ - \ No newline at end of file diff --git a/layout/_partial/comments/utterances/script.ejs b/layout/_partial/comments/utterances/script.ejs index a6febf3c2..4def2d7da 100644 --- a/layout/_partial/comments/utterances/script.ejs +++ b/layout/_partial/comments/utterances/script.ejs @@ -1,26 +1,23 @@ - diff --git a/layout/_partial/comments/waline/script.ejs b/layout/_partial/comments/waline/script.ejs index 5da6ead35..ce2be28a1 100644 --- a/layout/_partial/comments/waline/script.ejs +++ b/layout/_partial/comments/waline/script.ejs @@ -1,14 +1,16 @@ diff --git a/source/js/main.js b/source/js/main.js index 6c4ecaf74..4894426aa 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -58,6 +58,20 @@ const util = { scrollComment: () => { document.getElementById('comments').scrollIntoView({behavior: "smooth"}); }, + + viewportLazyload: (target, func, enabled = true) => { + if (!enabled || !("IntersectionObserver" in window)) { + func(); + return; + } + const observer = new IntersectionObserver((entries) => { + if (entries[0].intersectionRatio > 0) { + func(); + observer.disconnect(); + } + }); + observer.observe(target); + } } const hud = {