From 0f994eee95811f5cf6099fb5897dd62be1e6cff2 Mon Sep 17 00:00:00 2001
From: Aditya Telange <21258296+adityatelange@users.noreply.github.com>
Date: Thu, 24 Dec 2020 12:47:42 +0530
Subject: footer: change scroll behaviour as it was before 80954de fixes #151
anchored-headings: retain anchor link '#' in URL
cc #108
footer: remove '#' with go-to-top
Revert "anchored-headings: retain anchor link '#' in URL"
This reverts commit 80954de8bd085a3d5876e86c878088f911307c52.
Revert "footer: rm unused code"
This reverts commit c76233b350fde926c557e49b1a5f0bab8edddc55.
---
layouts/partials/footer.html | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
(limited to 'layouts/partials')
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 2482791..c384c4e 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -9,10 +9,14 @@
·
Theme PaperMod
-
+
+
+
{{- partial "extend_footer.html" . -}}
{{ if (and (in site.Params.mainSections .Type) (ne .Layout `archives`) (ne .Layout `search`)) }}
{{- if not .Site.Params.assets.disableFingerprinting }}
@@ -30,6 +34,20 @@
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
}
}
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
+ anchor.addEventListener("click", function (e) {
+ e.preventDefault();
+ var id = this.getAttribute("href").substr(1);
+ document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
+ behavior: "smooth"
+ });
+ if (id === "top") {
+ history.replaceState(null, null, " ");
+ } else {
+ history.replaceState(null, null, `#${id}`);
+ }
+ });
+ });
var mybutton = document.getElementById("top-link");
window.onscroll = function () {
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
@@ -40,11 +58,6 @@
mybutton.style.opacity = "0";
}
};
- mybutton.onclick = function () {
- document.body.scrollTop = 0;
- document.documentElement.scrollTop = 0;
- window.location.hash = ''
- }
function menu_on_scroll() {
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
--
cgit v1.2.3