diff --git a/src/theme/book.js b/src/theme/book.js index 8fda7a6cbe..bd16519cdb 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -408,7 +408,6 @@ function playpen_text(playpen) { (function sidebar() { var html = document.querySelector("html"); var sidebar = document.getElementById("sidebar"); - var sidebarScrollBox = document.querySelector(".sidebar-scrollbox"); var sidebarLinks = document.querySelectorAll('#sidebar a'); var sidebarToggleButton = document.getElementById("sidebar-toggle"); var sidebarResizeHandle = document.getElementById("sidebar-resize-handle"); @@ -507,7 +506,8 @@ function playpen_text(playpen) { // Scroll sidebar to current active section var activeSection = document.getElementById("sidebar").querySelector(".active"); if (activeSection) { - sidebarScrollBox.scrollTop = activeSection.offsetTop; + // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView + activeSection.scrollIntoView({ block: 'center' }); } })(); diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 8f586e01d1..291e279659 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -87,7 +87,7 @@