ux: add scroll position lock for default docs sidebar

This commit is contained in:
Henk Verlinde 2022-02-02 10:54:55 +01:00
parent 971894755e
commit 17eb9a6902
2 changed files with 15 additions and 1 deletions

View File

@ -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);
});
}

View File

@ -1,7 +1,7 @@
{{ define "main" }} {{ define "main" }}
<div class="row flex-xl-nowrap"> <div class="row flex-xl-nowrap">
<div class="col-lg-5 col-xl-4 docs-sidebar d-none d-lg-block"> <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" . }} {{ partial "sidebar/docs-menu.html" . }}
</nav> </nav>
</div> </div>