Skip to content

Commit

Permalink
scroll page index to active page
Browse files Browse the repository at this point in the history
  • Loading branch information
mirrorcult committed Sep 11, 2023
1 parent c1c2c01 commit da12838
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ window.addEventListener('load', function() {
var pagetoc = document.getElementsByClassName("pagetoc")[0];
var elements = document.getElementsByClassName("header");

/* Scroll the page index on the left to the current active page */
var active = document.querySelector(".chapter li a.active");
active.scrollIntoView({ behavior: "instant", block: "center", inline: "nearest" });

// don't show sidebar with only 1 header (or less)
if (elements.length <= 1)
return;
Expand Down

0 comments on commit da12838

Please sign in to comment.