0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 01:11:24 +01:00

Don't show/hide nav when clicking in docs sidebar

- Listens to hashchange event

- Changes only the navbar visibilty when scroll not triggered by hashchange

Resolves #2456
This commit is contained in:
thollander 2019-04-23 22:57:54 +02:00 committed by Conduitry
parent adcd13f6dd
commit 93f7ecca1d

View File

@ -35,12 +35,21 @@
};
});
// Prevents navbar to show/hide when clicking in docs sidebar
let hash_changed = false;
function handle_hashchange() {
hash_changed = true;
}
let last_scroll = 0;
function handle_scroll() {
const scroll = window.pageYOffset;
visible = (scroll < 50 || scroll < last_scroll);
if (!hash_changed) {
visible = (scroll < 50 || scroll < last_scroll);
}
last_scroll = scroll;
hash_changed = false;
}
</script>
@ -227,7 +236,7 @@
}
</style>
<svelte:window on:scroll={handle_scroll}/>
<svelte:window on:hashchange={handle_hashchange} on:scroll={handle_scroll} />
<header class:visible="{visible || open}">
<nav>