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: [PATCH] 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. --- assets/css/reset.css | 9 +-------- layouts/_default/baseof.html | 2 +- layouts/partials/footer.html | 31 ++++++++++++++++++++++--------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/assets/css/reset.css b/assets/css/reset.css index 1c9fbc04..f29d4e24 100644 --- a/assets/css/reset.css +++ b/assets/css/reset.css @@ -5,14 +5,7 @@ } html { - -webkit-tap-highlight-color: transparent; - scroll-behavior: smooth -} - -@media screen and (prefers-reduced-motion: reduce) { - html { - scroll-behavior: auto - } + -webkit-tap-highlight-color: transparent } a, diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 0103ffe2..45cf9042 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -12,7 +12,7 @@ {{- if eq $.Site.Params.defaultTheme `dark` -}} {{- print " dark" }} {{- end -}} -"> +" id="top"> {{- partialCached "header.html" . .Page}}
{{- block "main" . }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 24827911..c384c4ed 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);