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 }}
<script>
var throttle_pause = false;
var fetching = false;
var page_number = {{ $.Paginator.PageNumber }};
const total_pages = {{ $.Paginator.TotalPages }};
var throttle_pause = false;
var fetching = false;
var page_number = {{ $.Paginator.PageNumber }};
const total_pages = {{ $.Paginator.TotalPages }};
const throttle = (func, timeout) => {
const throttle = (func, timeout) => {
if (throttle_pause || fetching) return;
throttle_pause = true;
setTimeout(() => {
func();
throttle_pause = false;
}, timeout);
};
};
const loading_wrapper = document.querySelector(".loading-wrapper");
const loading_wrapper = document.querySelector(".loading-wrapper");
document.addEventListener("scroll", () => {
document.addEventListener("scroll", () => {
throttle(() => {
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;
@ -98,14 +98,14 @@ document.addEventListener("scroll", () => {
});
}
}, 250);
})
})
</script>
{{ end }}
{{ if .Site.Params.heti }}
<script>
const heti = new Heti(document);
heti.autoSpacing();
const heti = new Heti(document);
heti.autoSpacing();
</script>
{{ end }}