From bdb08dd14b688b22056e6b5105509609319a67f6 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sat, 17 Sep 2022 16:26:52 -0500 Subject: [PATCH] Fix TOC width issue --- src/templates/src/education_article.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/templates/src/education_article.html b/src/templates/src/education_article.html index 99d98b9b..1d22c7fc 100644 --- a/src/templates/src/education_article.html +++ b/src/templates/src/education_article.html @@ -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() {