Skip to content

Commit c256f3c

Browse files
committed
fix: Readjust anchor scroll offset on page load
1 parent 6125f56 commit c256f3c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

_assets/js/api-toc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ $(function () {
77
e.preventDefault();
88
animateScrolling(this.hash);
99
};
10-
10+
11+
// Detect hash on page load and readjust scroll offset
12+
var initialHash = window.location.hash;
13+
if (!!initialHash) {
14+
setTimeout(function(){
15+
animateScrolling(initialHash);
16+
}, 100);
17+
}
18+
1119
$("#markdown-toc")
1220
.on("click", "a", function () {
1321
$(".section > ul").hide();

_assets/js/toc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ $(function() {
5252
e.preventDefault();
5353
animateScrolling(this.hash);
5454
};
55-
55+
56+
// Detect hash on page load and readjust scroll offset
57+
var initialHash = window.location.hash;
58+
if (!!initialHash) {
59+
setTimeout(function(){
60+
animateScrolling(initialHash);
61+
}, 100);
62+
}
63+
5664
// animated scroll
5765
// Exclude the app inside the div.theme-preview since it's not in an <iframe/>,
5866
// leading to unwanted scrollTop when clicking on links inside the app.

0 commit comments

Comments
 (0)