Prevent the top bar from covering the heading when scrolling down (in mobile views)

This commit is contained in:
Cotes Chung 2022-01-05 22:56:33 +08:00
parent b0815b53c0
commit e7b377cf63
3 changed files with 76 additions and 65 deletions

View File

@ -21,8 +21,15 @@ $(function() {
.not("[href='#']") .not("[href='#']")
.not("[href='#0']") .not("[href='#0']")
.click(function(event) { .click(function(event) {
if (this.pathname.replace(/^\//, "") === location.pathname.replace(/^\//, "")) {
if (location.hostname === this.hostname) { if (this.pathname.replace(/^\//, "") !== location.pathname.replace(/^\//, "")) {
return;
}
if (location.hostname !== this.hostname) {
return;
}
const hash = decodeURI(this.hash); const hash = decodeURI(this.hash);
let toFootnoteRef = RegExp(/^#fnref:/).test(hash); let toFootnoteRef = RegExp(/^#fnref:/).test(hash);
let toFootnote = toFootnoteRef ? false : RegExp(/^#fn:/).test(hash); let toFootnote = toFootnoteRef ? false : RegExp(/^#fn:/).test(hash);
@ -33,7 +40,10 @@ $(function() {
let isAnchor = RegExp(/^H\d/).test(parent); let isAnchor = RegExp(/^H\d/).test(parent);
let isMobileViews = !$topbarTitle.is(":hidden"); let isMobileViews = !$topbarTitle.is(":hidden");
if (typeof $target !== "undefined") { if (typeof $target === "undefined") {
return;
}
event.preventDefault(); event.preventDefault();
if (history.pushState) { /* add hash to URL */ if (history.pushState) { /* add hash to URL */
@ -56,6 +66,11 @@ $(function() {
if ((isAnchor || toFootnoteRef) && isMobileViews) { if ((isAnchor || toFootnoteRef) && isMobileViews) {
destOffset -= topbarHeight; destOffset -= topbarHeight;
} }
} else {
if (isMobileViews) {
destOffset -= topbarHeight;
}
} }
$("html").animate({ $("html").animate({
@ -93,9 +108,5 @@ $(function() {
} }
} }
}); });
}
}
}
}); /* click() */ }); /* click() */
}); });

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long