Skip to content

Commit

Permalink
Add scroll to element
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale-Ko committed May 6, 2024
1 parent 3b00c93 commit c242723
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ async function fetchJsonCached(url, options) {
let body = document.querySelector("body");
body.classList.remove("loading");
body.classList.add("loaded");
if (window.location.hash.length > 0) {
let scrollElement = document.querySelector(window.location.hash);
if (scrollElement != undefined) {
scrollElement.scrollIntoView({ behavior: "smooth", block: "center" });
}
}
}
if (versionInfo.languages.filter(a => a.code == language).length > 0) {
let pageData = await fetchTextCached("/pages/" + language + "/" + page + ".md");
Expand Down
7 changes: 7 additions & 0 deletions scripts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ interface VersionInfo {
let body: HTMLBodyElement = document.querySelector("body") as HTMLBodyElement;
body.classList.remove("loading");
body.classList.add("loaded");

if (window.location.hash.length > 0) {
let scrollElement = document.querySelector(window.location.hash)
if (scrollElement != undefined) {
scrollElement.scrollIntoView({ behavior: "smooth", block: "center" });
}
}
}

if (versionInfo.languages.filter(a => a.code == language).length > 0) {
Expand Down

0 comments on commit c242723

Please sign in to comment.