Skip to content

Commit 679d58a

Browse files
committed
fix: article scrolling on larger displays
#26
1 parent 4c6ded2 commit 679d58a

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/layouts/WikiArticle.astro

+22-19
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,18 @@ export interface Props {
9494
<button class="open"><Icon name="list" group="solid" /></button>
9595
<button class="close"><Icon name="x" group="solid" /></button>
9696
<div class="title">Outline</div>
97-
<div class="content">
98-
<nav>
99-
<ol>
100-
<li><a href={`#${titleSlug}`}>{article.data.title}</a></li>
101-
{
102-
headings.map((heading) => (
103-
<li class={`depth-${heading.depth}`}>
104-
<a href={`#${heading.slug}`}>{heading.text}</a>
105-
</li>
106-
))
107-
}
108-
</ol>
109-
</nav>
110-
</div>
97+
<nav class="content">
98+
<ol>
99+
<li><a href={`#${titleSlug}`}>{article.data.title}</a></li>
100+
{
101+
headings.map((heading) => (
102+
<li class={`depth-${heading.depth}`}>
103+
<a href={`#${heading.slug}`}>{heading.text}</a>
104+
</li>
105+
))
106+
}
107+
</ol>
108+
</nav>
111109
</div>
112110
</div>
113111
</Layout>
@@ -155,16 +153,21 @@ export interface Props {
155153

156154
headings.forEach((heading) => intersectionObserver.observe(heading));
157155

158-
document.addEventListener(
159-
"scroll",
160-
lodash.debounce(() => {
161-
console.warn("INVOKE");
156+
const scrollOutline = lodash.debounce(
157+
() => {
162158
outline?.scrollTo({
163159
top: topLink.offsetTop - outline.clientHeight / 2,
164160
behavior: "smooth",
165161
});
166-
}, 10)
162+
},
163+
30,
164+
{ leading: false, trailing: true }
167165
);
166+
167+
document.addEventListener("scroll", scrollOutline);
168+
document
169+
.querySelector(".columns .center")
170+
?.addEventListener("scroll", scrollOutline);
168171
</script>
169172

170173
<style lang="scss">

0 commit comments

Comments
 (0)