This commit is contained in:
Jeffrey N. 2025-05-30 20:18:47 -07:00 committed by GitHub
commit 7920cb650c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View File

@ -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"] {

18
assets/book-header.js Normal file
View File

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

View File

@ -21,6 +21,13 @@
{{ partial "docs/inject/content-before" . }}
{{ template "main" . }} <!-- Page Content -->
<!-- Improve .book-header usability on mobile devices -->
{{ $script := resources.Get "book-header.js" | resources.Minify }}
{{ with $script.Content }}
<script>{{ . | safeJS }}</script>
{{ end }}
{{ partial "docs/inject/content-after" . }}
<footer class="book-footer">