Skip to content

Commit eac9a86

Browse files
committed
refactor: article outline scrolling
- Larger debounce wait time - Added scrollend listener to flush debounced function (in supported browsers) #26
1 parent ba9b35a commit eac9a86

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/layouts/WikiArticle.astro

+9-4
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,19 @@ export interface Props {
160160
behavior: "smooth",
161161
});
162162
},
163-
30,
163+
50,
164164
{ leading: false, trailing: true }
165165
);
166166

167+
const centerColumn =
168+
document.querySelector<HTMLDivElement>(".columns .center");
169+
167170
document.addEventListener("scroll", scrollOutline);
168-
document
169-
.querySelector(".columns .center")
170-
?.addEventListener("scroll", scrollOutline);
171+
centerColumn?.addEventListener("scroll", scrollOutline);
172+
173+
// Flush debounced outline scroll functions when scrollend is fired (if browser supports it)
174+
document.addEventListener("scrollend", () => scrollOutline.flush());
175+
centerColumn?.addEventListener("scrollend", () => scrollOutline.flush());
171176
</script>
172177

173178
<style lang="scss">

0 commit comments

Comments
 (0)