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);