Skip to content

Commit

Permalink
Fixed bug with scrollToId JS function (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
atteggiani authored Sep 23, 2024
1 parent a353096 commit 2f44727
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions docs/js/miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ function sortTables() {
function adjustScrollingToId() {
function scrollToId() {
if (location.hash) {
let header = document.querySelector('header');
let el = document.getElementById(location.hash.slice(1,));
let offset = el.getBoundingClientRect().top - header.getBoundingClientRect().bottom;
if (offset != 0) {
window.scrollBy(0, offset);
if (el) {
let header = document.querySelector('header');
let offset = el.getBoundingClientRect().top - header.getBoundingClientRect().bottom;
if (offset != 0) {
window.scrollBy(0, offset);
}
}
}
}
document.querySelectorAll(`[href^="#"]`).forEach(el => el.addEventListener("click",(e) => setTimeout(scrollToId,0), false));
scrollToId();
document.querySelectorAll(`[href^="#"]`).forEach(el => el.addEventListener("click",(e) => setTimeout(scrollToId,0), false));
}


Expand Down

0 comments on commit 2f44727

Please sign in to comment.