Skip to content

Commit 0f792aa

Browse files
committed
Update patch_scrollToActive.js
1 parent ef34571 commit 0f792aa

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

docs/_static/patch_scrollToActive.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,16 @@
2626
* Detect the active page in the sidebar, and scroll so that it is centered on
2727
* the screen.
2828
*/
29-
var scrollToActive = () => {
30-
var navbar = document.getElementById("site-navigation");
31-
var navbar_scrollable = navbar.children[0];
32-
var active_pages = navbar.querySelectorAll(".active");
33-
var active_page = active_pages[active_pages.length - 1];
34-
// Only scroll the navbar if the active link is lower than 50% of the page
35-
if (
36-
active_page !== undefined &&
37-
active_page.offsetTop > $(window).height() * 0.5
38-
) {
39-
navbar_scrollable.scrollTop =
40-
active_page.offsetTop - $(window).height() * 0.2;
29+
30+
var scrollToActive = () => {
31+
let navbar_scrollable = $("#site-navigation").children()[0];
32+
let active_navigation_item = $("#site-navigation .active").last();
33+
if (active_navigation_item) {
34+
if (active_navigation_item.offset().top > $(window).height() * 0.5) {
35+
navbar_scrollable.scrollTop = active_navigation_item.offset().top - $(window).height() * 0.2;
36+
}
4137
}
4238
};
4339

4440

4541
sbRunWhenDOMLoaded(scrollToActive);
46-
47-
$(document).ready(function() {
48-
console.debug("debug patch_scrollToActive")
49-
});

0 commit comments

Comments
 (0)