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 ) &&