Prevent the anchor of the heading from being awakened early

This commit is contained in:
Cotes Chung 2021-12-08 16:53:48 +08:00
parent 259d0deabc
commit 09742d40dd
3 changed files with 7 additions and 23 deletions

View file

@ -8,7 +8,6 @@
*/ */
$(function() { $(function() {
const REM = 16; /* 16px */
const $topbarTitle = $("#topbar-title"); const $topbarTitle = $("#topbar-title");
const topbarHeight = $("#topbar-wrapper").outerHeight(); const topbarHeight = $("#topbar-wrapper").outerHeight();
const SCROLL_MARK = "scroll-focus"; const SCROLL_MARK = "scroll-focus";
@ -40,27 +39,15 @@ $(function() {
let destOffset = $target.offset().top; let destOffset = $target.offset().top;
if (destOffset < curOffset) { // scroll up if (destOffset < curOffset) { // scroll up
if (toFootnoteRef) { if (!isAnchor && !toFootnote && $topbarTitle.is(":hidden")) { // the ToC item
// Avoid the top-bar covering `fnref` when scrolling up destOffset -= topbarHeight;
// because `fnref` has no `%anchor`(see: module.scss) style.
destOffset -= (topbarHeight + REM / 2);
}
if (isAnchor && $topbarTitle.is(":hidden")) {
destOffset += topbarHeight;
}
} else { // scroll down
if (!isAnchor && !toFootnote) { // the ToC item
destOffset += topbarHeight;
} }
} }
$("html,body").animate({ $("html,body").animate({
scrollTop: destOffset scrollTop: destOffset
}, 800, () => {
// const $target = $($target); }, 800, () => {
$target.focus(); $target.focus();
/* clean up old scroll mark */ /* clean up old scroll mark */

View file

@ -11,12 +11,9 @@
} }
%section { %section {
padding-top: 3.5rem;
margin-top: -2.5rem;
#core-wrapper & { #core-wrapper & {
line-height: 1.2; margin-top: 2.5rem;
margin-bottom: 1rem; margin-bottom: 2rem;
} }
} }
@ -24,7 +21,7 @@
> a { > a {
font-size: 70%; font-size: 70%;
visibility: hidden; visibility: hidden;
margin-left: 0.25rem; margin-left: 0.5rem;
border-bottom: none !important; border-bottom: none !important;
opacity: 0; opacity: 0;
transition: opacity 0.25s ease-in, visibility 0s ease-in 0.25s; transition: opacity 0.25s ease-in, visibility 0s ease-in 0.25s;

File diff suppressed because one or more lines are too long