prevent annoying sidebar scrolling glitch

pull/1929/head
Richard Harris 7 years ago
parent cfb6f52f2b
commit cd4f987f4e

@ -5,6 +5,7 @@
export let sections = []; export let sections = [];
export let active_section = null; export let active_section = null;
export let show_contents; export let show_contents;
export let prevent_sidebar_scroll = false;
onMount(() => { onMount(() => {
// ------------------------------------------ // ------------------------------------------
@ -42,8 +43,8 @@
afterUpdate(() => { afterUpdate(() => {
// bit of a hack — prevent sidebar scrolling if // bit of a hack — prevent sidebar scrolling if
// TOC is open on mobile // TOC is open on mobile, or scroll came from within sidebar
if (show_contents && window.innerWidth < 832) return; if (prevent_sidebar_scroll || show_contents && window.innerWidth < 832) return;
const active = ul.querySelector('.active'); const active = ul.querySelector('.active');
@ -97,7 +98,12 @@
.active { color: var(--prime) } .active { color: var(--prime) }
</style> </style>
<ul bind:this={ul} class="guide-toc"> <ul
bind:this={ul}
class="guide-toc"
on:mouseenter="{() => prevent_sidebar_scroll = true}"
on:mouseleave="{() => prevent_sidebar_scroll = false}"
>
{#each sections as section} {#each sections as section}
<li> <li>
<a class="section" class:active="{section.slug === active_section}" href="guide#{section.slug}"> <a class="section" class:active="{section.slug === active_section}" href="guide#{section.slug}">

Loading…
Cancel
Save