refractor code

This commit is contained in:
FarseaSH 2023-04-04 22:24:43 +08:00
parent d64d41e7e6
commit e55815f3d2

View file

@ -53,23 +53,23 @@
{{ if .Site.Params.infiniteScroll }} {{ if .Site.Params.infiniteScroll }}
<script> <script>
var throttle_pause = false; var throttle_pause = false;
var fetching = false; var fetching = false;
var page_number = {{ $.Paginator.PageNumber }}; var page_number = {{ $.Paginator.PageNumber }};
const total_pages = {{ $.Paginator.TotalPages }}; const total_pages = {{ $.Paginator.TotalPages }};
const throttle = (func, timeout) => { const throttle = (func, timeout) => {
if (throttle_pause || fetching) return; if (throttle_pause || fetching) return;
throttle_pause = true; throttle_pause = true;
setTimeout(() => { setTimeout(() => {
func(); func();
throttle_pause = false; throttle_pause = false;
}, timeout); }, timeout);
}; };
const loading_wrapper = document.querySelector(".loading-wrapper"); const loading_wrapper = document.querySelector(".loading-wrapper");
document.addEventListener("scroll", () => { document.addEventListener("scroll", () => {
throttle(() => { throttle(() => {
const last_moment = document.querySelector(".page > .container .moment-row:last-child"); const last_moment = document.querySelector(".page > .container .moment-row:last-child");
const page_end = window.innerHeight + window.pageYOffset + 100 + last_moment.offsetHeight >= document.body.offsetHeight; const page_end = window.innerHeight + window.pageYOffset + 100 + last_moment.offsetHeight >= document.body.offsetHeight;
@ -98,14 +98,14 @@ document.addEventListener("scroll", () => {
}); });
} }
}, 250); }, 250);
}) })
</script> </script>
{{ end }} {{ end }}
{{ if .Site.Params.heti }} {{ if .Site.Params.heti }}
<script> <script>
const heti = new Heti(document); const heti = new Heti(document);
heti.autoSpacing(); heti.autoSpacing();
</script> </script>
{{ end }} {{ end }}