theme: scroll to heading on initial load #232

This commit is contained in:
Sören Weber 2022-04-02 15:30:43 +02:00
parent 0dd92e332b
commit cadc808932
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589

View file

@ -484,7 +484,7 @@ function initSwipeHandler(){
function scrollToActiveMenu() {
window.setTimeout(function(){
var e = $("#sidebar ul.topics li.active a")[0];
var e = document.querySelector( '#sidebar ul.topics li.active a' );
if( e && e.scrollIntoView ){
e.scrollIntoView({
block: 'center',
@ -493,6 +493,20 @@ function scrollToActiveMenu() {
}, 10);
}
function scrollToFragment() {
if( !window.location.hash || window.location.hash.length <= 1 ){
return;
}
window.setTimeout(function(){
var e = document.querySelector( window.location.hash );
if( e && e.scrollIntoView ){
e.scrollIntoView({
block: 'start',
});
}
}, 10);
}
// Get Parameters from some url
var getUrlParameter = function getUrlParameter(sPageURL) {
var url = sPageURL.split('?');
@ -544,6 +558,7 @@ jQuery(function() {
initSwagger();
initMenuScrollbar();
scrollToActiveMenu();
scrollToFragment();
initLightbox();
initImageStyles();
initToc();