Skip to content

Commit 6879289

Browse files
committed
Resize the toc in javascript to fit the remaing visible area
1 parent a2259ab commit 6879289

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

markdown/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ <h2>Table of Contents</h2>
346346
if (document.location.hash.includes('#')) {
347347
document.location.hash = document.location.hash;
348348
}
349+
350+
updateTocSize();
349351
}
350352
}
351353

@@ -474,6 +476,19 @@ <h2>Table of Contents</h2>
474476
}
475477
}
476478

479+
function updateTocSize() {
480+
const toc = document.getElementById('toc');
481+
const tocInner = document.getElementById('table-of-contents');
482+
if (toc != null && tocInner != null) {
483+
const height = window.document.documentElement.clientHeight;
484+
tocInner.style.maxHeight = `${height - tocInner.getBoundingClientRect().top - 20}px`;
485+
toc.style.maxHeight = `${height - toc.getBoundingClientRect().top - 20}px`;
486+
}
487+
}
488+
489+
window.onscroll = updateTocSize;
490+
window.onresize = updateTocSize;
491+
477492
//]]>
478493
</script>
479494

0 commit comments

Comments
 (0)