mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-24 06:24:22 +00:00
refactor(core): use scroll-padding-top
for top margin
This commit is contained in:
parent
1be7f5faaf
commit
9d711d4ee2
|
@ -41,15 +41,23 @@ function changeActiveSection( id ) {
|
|||
* @return {void}
|
||||
*/
|
||||
function initToC() {
|
||||
const
|
||||
header = document.querySelector( '.citizen-header' ),
|
||||
bodyContent = document.getElementById( 'bodyContent' );
|
||||
const bodyContent = document.getElementById( 'bodyContent' );
|
||||
|
||||
// We use scroll-padding-top to handle scrolling with fixed header
|
||||
// It is better to respect that so it is consistent
|
||||
const getTopMargin = () => {
|
||||
return Number(
|
||||
window.getComputedStyle( document.documentElement )
|
||||
.getPropertyValue( 'scroll-padding-top' )
|
||||
.slice( 0, -2 )
|
||||
) + 20;
|
||||
};
|
||||
|
||||
const initSectionObserver = require( './sectionObserver.js' ).init;
|
||||
|
||||
const sectionObserver = initSectionObserver( {
|
||||
elements: bodyContent.querySelectorAll( '.mw-headline' ),
|
||||
topMargin: header.getBoundingClientRect().height,
|
||||
topMargin: getTopMargin(),
|
||||
onIntersection: ( section ) => { changeActiveSection( section.id ); }
|
||||
} );
|
||||
|
||||
|
|
Loading…
Reference in a new issue