MediaWiki:Common.js: Difference between revisions
From Maps for MediaWiki
No edit summary |
mNo edit summary |
||
Line 19: | Line 19: | ||
hash = hash || window.location.hash; | hash = hash || window.location.hash; | ||
var $target = $( hash ), | var $target = $( hash ), | ||
headerHeight = $header.outerHeight() + | headerHeight = $header.outerHeight() + 7; | ||
if ( $target.length ) { | if ( $target.length ) { |
Revision as of 09:42, 1 August 2020
/* Any JavaScript here will be loaded for all users on every page load. */
( function () {
$( function () {
var $header = $( 'div.p-navbar.sticky:visible' );
if ( !$header.length ) {
return;
}
$( 'a[href*="#"]:not([href="#"])' ).click( function () {
adjustScroll( $header, this.hash );
} );
$( window ).on( 'hashchange', function ( e ) {
adjustScroll( $header );
} );
} );
function adjustScroll( $header, hash, animate ) {
hash = hash || window.location.hash;
var $target = $( hash ),
headerHeight = $header.outerHeight() + 7;
if ( $target.length ) {
$( 'html,body' ).animate( {
scrollTop: $target.offset().top - headerHeight
}, 500 );
return false;
}
}
}() );