diff --git a/assets/_main.scss b/assets/_main.scss
index 25eed41..409c731 100644
--- a/assets/_main.scss
+++ b/assets/_main.scss
@@ -305,9 +305,16 @@ body[dir="rtl"] .book-menu {
}
@media screen and (max-width: $mobile-breakpoint) {
+ h1, h2, h3, h4, h5, h6 {
+ scroll-margin-top: 3rem;
+ }
+
#menu-control,
#toc-control {
display: inline;
+ // prevents scrolling to top when inputs focused
+ position: fixed;
+ top: 0;
}
.book-menu {
@@ -321,7 +328,16 @@ body[dir="rtl"] .book-menu {
}
.book-header {
+ background: var(--body-background);
+ border-bottom: 2px solid var(--color-visited-link);
display: block;
+ max-height: 100vh;
+ overflow: auto;
+ padding: .35rem 0;
+ position: sticky;
+ top: -1px;
+ // prevent background from being transparent
+ z-index: 1;
}
#menu-control:focus ~ main label[for="menu-control"] {
diff --git a/assets/book-header.js b/assets/book-header.js
new file mode 100644
index 0000000..fd3eee5
--- /dev/null
+++ b/assets/book-header.js
@@ -0,0 +1,18 @@
+(function () {
+ let tocLinks = document.querySelectorAll("#TableOfContents li");
+ let tocInput = document.getElementById("toc-control");
+ tocLinks.forEach(l =>
+ l.addEventListener("click",
+ () => tocInput.checked = false));
+})();
+(function () {
+ let menuLabel = document.querySelector("label[for='menu-control']");
+ let menuInput = document.getElementById("menu-control");
+ let tocInput = document.getElementById("toc-control");
+ menuLabel.addEventListener("click",
+ function () {
+ if (!menuInput.checked) {
+ tocInput.checked = false;
+ }
+ });
+})();
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index a6c4c07..15f8390 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -21,6 +21,13 @@
{{ partial "docs/inject/content-before" . }}
{{ template "main" . }}
+
+
+ {{ $script := resources.Get "book-header.js" | resources.Minify }}
+ {{ with $script.Content }}
+
+ {{ end }}
+
{{ partial "docs/inject/content-after" . }}