mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-24 14:34:09 +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}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function initToC() {
|
function initToC() {
|
||||||
const
|
const bodyContent = document.getElementById( 'bodyContent' );
|
||||||
header = document.querySelector( '.citizen-header' ),
|
|
||||||
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 initSectionObserver = require( './sectionObserver.js' ).init;
|
||||||
|
|
||||||
const sectionObserver = initSectionObserver( {
|
const sectionObserver = initSectionObserver( {
|
||||||
elements: bodyContent.querySelectorAll( '.mw-headline' ),
|
elements: bodyContent.querySelectorAll( '.mw-headline' ),
|
||||||
topMargin: header.getBoundingClientRect().height,
|
topMargin: getTopMargin(),
|
||||||
onIntersection: ( section ) => { changeActiveSection( section.id ); }
|
onIntersection: ( section ) => { changeActiveSection( section.id ); }
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue