Skip to content

Commit

Permalink
Merge pull request #648 from h-enk/scroll-lock
Browse files Browse the repository at this point in the history
Adds scroll position lock for default docs sidebar
  • Loading branch information
h-enk authored Feb 2, 2022
2 parents 9718947 + 17eb9a6 commit 5466150
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Adds scroll position lock for default docs sidebar

if (document.querySelector('#sidebar-default') !== null) {
let sidebar = document.getElementById('sidebar-default');

let pos = sessionStorage.getItem('sidebar-scroll');
if (pos !== null) {
sidebar.scrollTop = parseInt(pos, 10);
}

window.addEventListener('beforeunload', () => {
sessionStorage.setItem('sidebar-scroll', sidebar.scrollTop);
});
}
2 changes: 1 addition & 1 deletion layouts/docs/single.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "main" }}
<div class="row flex-xl-nowrap">
<div class="col-lg-5 col-xl-4 docs-sidebar d-none d-lg-block">
<nav class="docs-links" aria-label="Main navigation">
<nav {{ if eq .Site.Params.menu.section.collapsibleSidebar false }}id="sidebar-default" {{ end }}class="docs-links" aria-label="Main navigation">
{{ partial "sidebar/docs-menu.html" . }}
</nav>
</div>
Expand Down

0 comments on commit 5466150

Please sign in to comment.