Merge branch 'master' of git.handmade.network:hmn/hmn

This commit is contained in:
Asaf Gartner 2022-09-18 22:25:09 +03:00
commit 4b9fe628e6
1 changed files with 6 additions and 2 deletions

View File

@ -74,11 +74,13 @@
// TOC
const FUDGE = 100;
const TOC_TOP_SPACING = 20;
document.addEventListener('scroll', () => {
function updateTOC() {
// Stickiness
const sidebarWidth = sidebar.clientWidth;
const stick = window.pageYOffset > sidebar.offsetTop-TOC_TOP_SPACING;
tocContainer.style.position = stick ? 'fixed' : 'static';
tocContainer.style.top = `${TOC_TOP_SPACING}px`;
tocContainer.style.width = `${sidebarWidth}px`;
// Active items
let activeEntry = null;
@ -95,7 +97,9 @@
if (activeEntry) {
activeEntry.link.classList.add('active');
}
});
}
document.addEventListener('scroll', updateTOC);
window.addEventListener('resize', updateTOC);
// Notes
function toggleNotes() {