mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2023-12-21 10:22:58 +01:00
menu : save menu scroll position in localstorage
(ux improve)
This commit is contained in:
parent
274688f238
commit
e17d61b46c
@ -16,6 +16,11 @@
|
||||
{{ $highlight := resources.Get "js/highlight.min.js" | minify | fingerprint}}
|
||||
<script src="{{ $highlight.Permalink }}" integrity="{{ $highlight.Data.Integrity }}"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
if (localStorage.getItem("menu-scroll-position")) {
|
||||
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
|
||||
}
|
||||
}
|
||||
hljs.initHighlightingOnLoad();
|
||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
anchor.addEventListener("click", function (e) {
|
||||
@ -36,4 +41,7 @@
|
||||
mybutton.style.opacity = "0";
|
||||
}
|
||||
};
|
||||
function menu_on_scroll() {
|
||||
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
|
||||
}
|
||||
</script>
|
@ -11,7 +11,7 @@
|
||||
<p class="logo"><a href="{{ "" | absURL }}">{{ .Site.Title }}</a></p>
|
||||
{{- end }}
|
||||
{{- if .Site.Menus.main }}
|
||||
<ul class="menu">
|
||||
<ul class="menu" id="menu" onscroll="menu_on_scroll()">
|
||||
{{- range .Site.Menus.main }}
|
||||
<li>
|
||||
<a href="{{ .URL }}">{{ .Name }}</a>
|
||||
|
Loading…
Reference in New Issue
Block a user