From 0746895e9bf70ac32f2ac89cb974ddbaf84fd027 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Mon, 8 Mar 2021 15:02:20 -0500 Subject: [PATCH] fix: incorrect ToC scrollspy highlight --- .../skins.citizen.scripts.toc.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/skins.citizen.scripts.toc/skins.citizen.scripts.toc.js b/resources/skins.citizen.scripts.toc/skins.citizen.scripts.toc.js index 1bf8bb61..b5a641b2 100644 --- a/resources/skins.citizen.scripts.toc/skins.citizen.scripts.toc.js +++ b/resources/skins.citizen.scripts.toc/skins.citizen.scripts.toc.js @@ -35,11 +35,17 @@ function SmoothScroll() { * @constructor */ function ScrollSpy() { - var sections = document.querySelectorAll( '.mw-headline' ); + var sections = document.querySelectorAll( '.mw-headline' ), + mwbody = document.querySelector( '.mw-body' ), + mwbodyStyle = window.getComputedStyle( mwbody ), + scrollOffset = parseInt( mwbodyStyle.marginTop, 10 ) + 1; + window.addEventListener( 'scroll', function () { var scrollPos = document.documentElement.scrollTop || document.body.scrollTop, section, id, node, active; + scrollPos += scrollOffset; + for ( section in sections ) { if ( Object.prototype.hasOwnProperty.call( sections, section ) &&