Auto scroll sticky ToC with content (#3115)

This commit is contained in:
iBug 2024-05-05 01:05:21 +08:00 committed by GitHub
parent 7ef6af66e4
commit dc41016c62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View File

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

File diff suppressed because one or more lines are too long