#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

@ -2,3 +2,6 @@
{{ with .Site.GetPage .Site.Params.BookMenuBundle }}
{{- .Content -}}
{{ end }}
{{ if .Site.Params.BookEnableJS }}
{{- template "jsmenu" . -}}
{{ end }}

View file

@ -24,3 +24,16 @@
}
</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 }}