Skip to content

Commit

Permalink
Don't show/hide nav when clicking in docs sidebar
Browse files Browse the repository at this point in the history
- Listens to hashchange event

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

Resolves sveltejs#2456
  • Loading branch information
thollander authored and Conduitry committed Apr 24, 2019
1 parent adcd13f commit 93f7ecc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions site/src/components/TopNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 93f7ecc

Please sign in to comment.