mirror of
https://github.com/Wonderfall/hugo-WonderMod.git
synced 2024-11-25 20:11:37 +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}}
|
{{ $highlight := resources.Get "js/highlight.min.js" | minify | fingerprint}}
|
||||||
<script src="{{ $highlight.Permalink }}" integrity="{{ $highlight.Data.Integrity }}"></script>
|
<script src="{{ $highlight.Permalink }}" integrity="{{ $highlight.Data.Integrity }}"></script>
|
||||||
<script>
|
<script>
|
||||||
|
window.onload = function () {
|
||||||
|
if (localStorage.getItem("menu-scroll-position")) {
|
||||||
|
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
|
||||||
|
}
|
||||||
|
}
|
||||||
hljs.initHighlightingOnLoad();
|
hljs.initHighlightingOnLoad();
|
||||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||||
anchor.addEventListener("click", function (e) {
|
anchor.addEventListener("click", function (e) {
|
||||||
@ -36,4 +41,7 @@
|
|||||||
mybutton.style.opacity = "0";
|
mybutton.style.opacity = "0";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
function menu_on_scroll() {
|
||||||
|
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
@ -11,7 +11,7 @@
|
|||||||
<p class="logo"><a href="{{ "" | absURL }}">{{ .Site.Title }}</a></p>
|
<p class="logo"><a href="{{ "" | absURL }}">{{ .Site.Title }}</a></p>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Site.Menus.main }}
|
{{- if .Site.Menus.main }}
|
||||||
<ul class="menu">
|
<ul class="menu" id="menu" onscroll="menu_on_scroll()">
|
||||||
{{- range .Site.Menus.main }}
|
{{- range .Site.Menus.main }}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ .URL }}">{{ .Name }}</a>
|
<a href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user