fix: incorrect ToC scrollspy highlight

This commit is contained in:
alistair3149 2021-03-08 15:02:20 -05:00 committed by GitHub
parent 09b399ccf0
commit 0746895e9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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