From 3ea46e531ba4457dc6bee57775b88fc14e903619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=BF=E7=AB=A0?= Date: Fri, 11 Oct 2019 12:01:14 +0800 Subject: [PATCH 1/4] Fix: Scroll sidebar to current active section (#1067) --- src/theme/book.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/theme/book.js b/src/theme/book.js index 8fda7a6cbe..2fd4a3b52c 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -505,10 +505,12 @@ function playpen_text(playpen) { }, { passive: true }); // Scroll sidebar to current active section - var activeSection = document.getElementById("sidebar").querySelector(".active"); - if (activeSection) { - sidebarScrollBox.scrollTop = activeSection.offsetTop; - } + window.addEventListener('load', function() { + var activeSection = document.getElementById("sidebar").querySelector(".active"); + if (activeSection) { + activeSection.scrollIntoViewIfNeeded(); + } + }); })(); (function chapterNavigation() { From db2d574dccc43196a9f9662b2ab8b09d8bcc6938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=BF=E7=AB=A0?= Date: Fri, 11 Oct 2019 14:32:59 +0800 Subject: [PATCH 2/4] Clean: Some code related to PR #1052 --- src/theme/book.js | 1 - src/theme/index.hbs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/theme/book.js b/src/theme/book.js index 2fd4a3b52c..09325e1e4c 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"); 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 @@