#24: Add JS script to keep menu on same position on reload

This commit is contained in:
Alex Shpak 2019-02-20 00:28:16 +01:00
parent d9961ece4e
commit dd0f7f7a5e
2 changed files with 16 additions and 0 deletions

View file

@ -1,4 +1,7 @@
{{- template "hrefhack" . -}} {{- template "hrefhack" . -}}
{{ with .Site.GetPage .Site.Params.BookMenuBundle }} {{ with .Site.GetPage .Site.Params.BookMenuBundle }}
{{- .Content -}} {{- .Content -}}
{{ end }}
{{ if .Site.Params.BookEnableJS }}
{{- template "jsmenu" . -}}
{{ end }} {{ end }}

View file

@ -23,4 +23,17 @@
color: {{ default "#004ed0" .Site.Params.BookMenuBundleActiveLinkColor }}; color: {{ default "#004ed0" .Site.Params.BookMenuBundleActiveLinkColor }};
} }
</style> </style>
{{ end }}
{{ define "jsmenu" }}
<script>
(function() {
var menu = document.querySelector('aside.book-menu nav')
addEventListener('beforeunload', function(event) {
localStorage.setItem('menu.scrollTop', menu.scrollTop)
});
menu.scrollTop = localStorage.getItem('menu.scrollTop')
})()
</script>
{{ end }} {{ end }}