mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 15:31:52 +00:00
✨ Feat: Prevent ToC flicker on initial load
Use CSS to control ToC height instead of JavaScript to prevent flickering.
This commit is contained in:
@@ -1507,8 +1507,8 @@ body.zen-mode-enable {
|
|||||||
.overflow-visible {
|
.overflow-visible {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
.overflow-y-scroll {
|
.overflow-y-auto {
|
||||||
overflow-y: scroll;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
.overscroll-contain {
|
.overscroll-contain {
|
||||||
overscroll-behavior: contain;
|
overscroll-behavior: contain;
|
||||||
@@ -3537,6 +3537,11 @@ body a, body button {
|
|||||||
#TableOfContents {
|
#TableOfContents {
|
||||||
max-width: 25vw;
|
max-width: 25vw;
|
||||||
}
|
}
|
||||||
|
#TOCView {
|
||||||
|
max-height: calc(100vh - 150px);
|
||||||
|
min-height: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
.toc ul, .toc li {
|
.toc ul, .toc li {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding-inline: calc(var(--spacing) * 0);
|
padding-inline: calc(var(--spacing) * 0);
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ body button {
|
|||||||
max-width: 25vw;
|
max-width: 25vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#TOCView {
|
||||||
|
max-height: calc(100vh - 150px);
|
||||||
|
min-height: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.toc ul,
|
.toc ul,
|
||||||
.toc li {
|
.toc li {
|
||||||
@apply px-0 leading-snug list-none;
|
@apply px-0 leading-snug list-none;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<details open id="TOCView"
|
<details open id="TOCView" class="toc-right mt-0 overflow-y-auto overscroll-contain scrollbar-thin scrollbar-track-neutral-200 scrollbar-thumb-neutral-400 dark:scrollbar-track-neutral-800 dark:scrollbar-thumb-neutral-600 rounded-lg ltr:-ml-5 ltr:pl-5 rtl:-mr-5 rtl:pr-5 hidden lg:block">
|
||||||
class="toc-right mt-0 overflow-y-scroll overscroll-contain scrollbar-thin scrollbar-track-neutral-200 scrollbar-thumb-neutral-400 dark:scrollbar-track-neutral-800 dark:scrollbar-thumb-neutral-600 rounded-lg ltr:-ml-5 ltr:pl-5 rtl:-mr-5 rtl:pr-5 hidden lg:block">
|
|
||||||
<summary
|
<summary
|
||||||
class="block py-1 text-lg font-semibold cursor-pointer bg-neutral-100 text-neutral-800 ltr:-ml-5 ltr:pl-5 rtl:-mr-5 rtl:pr-5 dark:bg-neutral-700 dark:text-neutral-100 lg:hidden">
|
class="block py-1 text-lg font-semibold cursor-pointer bg-neutral-100 text-neutral-800 ltr:-ml-5 ltr:pl-5 rtl:-mr-5 rtl:pr-5 dark:bg-neutral-700 dark:text-neutral-100 lg:hidden">
|
||||||
{{ i18n "article.table_of_contents" }}
|
{{ i18n "article.table_of_contents" }}
|
||||||
@@ -21,32 +20,7 @@
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var margin = 200;
|
|
||||||
var marginError = 50;
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
var $window = $(window);
|
|
||||||
var $toc = $('#TOCView');
|
|
||||||
var tocHeight = $toc.height();
|
|
||||||
|
|
||||||
function onResize() {
|
|
||||||
var windowAndMarginHeight = $window.height() - margin;
|
|
||||||
if(tocHeight >= windowAndMarginHeight) {
|
|
||||||
$toc.css("overflow-y", "scroll")
|
|
||||||
$toc.css("max-height", (windowAndMarginHeight + marginError) + "px")
|
|
||||||
} else {
|
|
||||||
$toc.css("overflow-y", "hidden")
|
|
||||||
$toc.css("max-height", "9999999px")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$window.on('resize', onResize);
|
|
||||||
$(document).ready(onResize);
|
|
||||||
})();
|
|
||||||
|
|
||||||
{{ if .Site.Params.smartTOC }}
|
{{ if .Site.Params.smartTOC }}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var $toc = $('#TableOfContents');
|
var $toc = $('#TableOfContents');
|
||||||
if ($toc.length > 0) {
|
if ($toc.length > 0) {
|
||||||
@@ -72,7 +46,7 @@
|
|||||||
$(e).removeClass('active');
|
$(e).removeClass('active');
|
||||||
{{ end }}
|
{{ end }}
|
||||||
});
|
});
|
||||||
$toc.find('a[href="#' + id + '"]').addClass('active')
|
$toc.find('a[href="#' + id + '"]').addClass('active');
|
||||||
$toc.find('a[href="#' + id + '"]').parentsUntil('#TableOfContents').each(function (i, e) {
|
$toc.find('a[href="#' + id + '"]').parentsUntil('#TableOfContents').each(function (i, e) {
|
||||||
$(e).children('a').parents('ul').show();
|
$(e).children('a').parents('ul').show();
|
||||||
});
|
});
|
||||||
@@ -88,5 +62,4 @@
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user