Skip to content

Commit

Permalink
Merge pull request #28 from asaage/asaage-patch-1
Browse files Browse the repository at this point in the history
take scroll-margin-top into account when scrolling via jump-anchor
  • Loading branch information
denniserdmann authored Jan 26, 2024
2 parents e78eefd + 78b68b2 commit 33175d8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Resources/public/onepage_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ function Onepage(list, options) {

// figure out element to scroll to
let target = anchor.hash;
let article = document.getElementById(anchor.hash.slice(1)).offsetTop;
let article = document.getElementById(anchor.hash.slice(1));
let position = article.offsetTop - parseInt(getComputedStyle(article).scrollMarginTop);

if (target.length) {
// only prevent default if animation is actually gonna happen
event.preventDefault();

// scroll to selected article
scrollTo({
top: article,
top: position,
behavior: "smooth"
});

Expand Down

0 comments on commit 33175d8

Please sign in to comment.