one last javascript fix

This commit is contained in:
Spax
2025-11-02 15:04:39 -07:00
parent 2784f5a103
commit 6bb664039f

View File

@@ -130,7 +130,8 @@ function saveScroll() {
// it returns to scroll positions stored in the array "scrollPos" // it returns to scroll positions stored in the array "scrollPos"
function returnScroll() { function returnScroll() {
document.getElementById("return").addEventListener("click", () => { const ret = document.getElementById("return");
ret.addEventListener("click", () => {
const scrollArray = JSON.parse(sessionStorage.getItem("scrollPos") ?? "[]").map(num => Number(num)); const scrollArray = JSON.parse(sessionStorage.getItem("scrollPos") ?? "[]").map(num => Number(num));
// check if saved, otherwise goto top and remove back arrow // check if saved, otherwise goto top and remove back arrow
@@ -140,13 +141,13 @@ function returnScroll() {
window.scroll(0, pos); window.scroll(0, pos);
} }
else if (scrollArray.length === 1) { else if (scrollArray.length === 1) {
this.classList.remove("show"); ret.classList.remove("show");
let pos = scrollArray.shift(); let pos = scrollArray.shift();
sessionStorage.setItem("scrollPos", JSON.stringify(scrollArray)); sessionStorage.setItem("scrollPos", JSON.stringify(scrollArray));
// scroll to top // scroll to top
window.scroll(0, pos); window.scroll(0, pos);
} else { } else {
this.classList.remove("show"); ret.classList.remove("show");
// scroll to top // scroll to top
window.scroll(0, 0); window.scroll(0, 0);
} }