Skip to content

Commit d28e57d

Browse files
Copilotsarzhann
andcommitted
Fix sidebar scroll: use offsetTop relative to sidebar instead of scrollIntoView
Co-authored-by: sarzhann <32760183+sarzhann@users.noreply.github.com> Agent-Logs-Url: https://github.com/vespa-engine/documentation/sessions/7dcf5901-91bf-45f0-8d73-27a8ab69629d
1 parent 98efbbb commit d28e57d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

_includes/sidebar.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,14 @@
167167
});
168168
});
169169

170-
const current = document.querySelector('#sidebar .sidebar-current');
171-
if (current) current.scrollIntoView({ block: 'nearest' });
170+
const sidebar = document.getElementById('sidebar');
171+
const current = sidebar && sidebar.querySelector('.sidebar-current');
172+
if (sidebar && current) {
173+
const sidebarRect = sidebar.getBoundingClientRect();
174+
const currentRect = current.getBoundingClientRect();
175+
const offset = currentRect.top - sidebarRect.top + sidebar.scrollTop;
176+
sidebar.scrollTop = offset - sidebar.clientHeight / 2 + currentRect.height / 2;
177+
}
172178

173179
function setNavbarHeight() {
174180
const nav = document.querySelector('nav.sticky-top');

0 commit comments

Comments
 (0)