Skip to content

Commit

Permalink
Merge pull request #377 from james2doyle/missing-headings
Browse files Browse the repository at this point in the history
Fixed: reduce margins and only pay attention to menu anchors
  • Loading branch information
shalvah authored Dec 21, 2021
2 parents 135bbd4 + 3e02198 commit 028d606
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions resources/js/theme-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ document.addEventListener('DOMContentLoaded', function() {

throttledUpdateHash(entries[0].target.id);
}, {
rootMargin: '-8% 0px -8% 0px', // shrink the intersection viewport
rootMargin: '0px 0px -12% 0px', // shrink the intersection viewport
threshold: 1.0, // trigger at 100% visibility
});

function makeObserver(elem) {
return observer.observe(elem);
}

const titles = document.querySelectorAll('.content h1, .content h2');
Array.from(titles).forEach(makeObserver);
// find all links in the menu
const menuItems = document.querySelectorAll('#toc a[href]');
// make observers for those links
Array.from(menuItems).forEach((aTag) => {
const title = document.querySelector(aTag.getAttribute('href'));
makeObserver(title);
});

const navButton = document.getElementById('nav-button');
const menuWrapper = document.querySelector('.tocify-wrapper');
Expand Down

0 comments on commit 028d606

Please sign in to comment.