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 80954de8bd.

Revert "footer: rm unused code"
This reverts commit c76233b350.
This commit is contained in:
Aditya Telange 2020-12-24 12:47:42 +05:30
parent 7c53c14c85
commit 0f994eee95
3 changed files with 24 additions and 18 deletions

View File

@ -5,14 +5,7 @@
} }
html { html {
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent
scroll-behavior: smooth
}
@media screen and (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto
}
} }
a, a,

View File

@ -12,7 +12,7 @@
{{- if eq $.Site.Params.defaultTheme `dark` -}} {{- if eq $.Site.Params.defaultTheme `dark` -}}
{{- print " dark" }} {{- print " dark" }}
{{- end -}} {{- end -}}
"> " id="top">
{{- partialCached "header.html" . .Page}} {{- partialCached "header.html" . .Page}}
<main class="main"> <main class="main">
{{- block "main" . }} {{- block "main" . }}

View File

@ -9,10 +9,14 @@
<span>&middot;</span> <span>&middot;</span>
<span>Theme <a href="https://git.io/hugopapermod" rel="noopener" target="_blank">PaperMod</a></span> <span>Theme <a href="https://git.io/hugopapermod" rel="noopener" target="_blank">PaperMod</a></span>
</footer> </footer>
<button class="top-link" id="top-link" type="button" aria-label="go to top" title="Go to Top (Alt + G)" accesskey="g"> <a href="#top">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6"> <button class="top-link" id="top-link" type="button" aria-label="go to top" title="Go to Top (Alt + G)"
<path d="M12 6H0l6-6z" /></svg> accesskey="g">
</button> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6">
<path d="M12 6H0l6-6z" />
</svg>
</button>
</a>
{{- partial "extend_footer.html" . -}} {{- partial "extend_footer.html" . -}}
{{ if (and (in site.Params.mainSections .Type) (ne .Layout `archives`) (ne .Layout `search`)) }} {{ if (and (in site.Params.mainSections .Type) (ne .Layout `archives`) (ne .Layout `search`)) }}
{{- if not .Site.Params.assets.disableFingerprinting }} {{- if not .Site.Params.assets.disableFingerprinting }}
@ -30,6 +34,20 @@
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position"); 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"); var mybutton = document.getElementById("top-link");
window.onscroll = function () { window.onscroll = function () {
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) { if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
@ -40,11 +58,6 @@
mybutton.style.opacity = "0"; mybutton.style.opacity = "0";
} }
}; };
mybutton.onclick = function () {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
window.location.hash = ''
}
function menu_on_scroll() { function menu_on_scroll() {
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft); localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);