Skip to content

Commit

Permalink
Auto scroll sticky ToC with content (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed May 4, 2024
1 parent 7ef6af6 commit dc41016
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions assets/js/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ $(function() {
});
}

// Auto scroll sticky ToC with content
document.addEventListener("gumshoeActivate", function (event) {
var target = event.target;
var scrollOptions = { behavior: "auto", block: "nearest", inline: "start" };

var tocElement = document.querySelector("aside.sidebar__right.sticky");
if (!tocElement) return;
if (!window.getComputedStyle(tocElement).position !== "sticky") return;

if (target.parentElement.classList.contains("toc__menu") && target == target.parentElement.firstElementChild) {
// Scroll to top instead
document.querySelector("nav.toc header").scrollIntoView(scrollOptions);
} else {
target.scrollIntoView(scrollOptions);
}
});

// add lightbox class to all image links
$(
"a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif'],a[href$='.webp']"
Expand Down
4 changes: 2 additions & 2 deletions assets/js/main.min.js

Large diffs are not rendered by default.

0 comments on commit dc41016

Please sign in to comment.