#24: Add JS script to keep menu on same position on reload
This commit is contained in:
parent
d9961ece4e
commit
dd0f7f7a5e
2 changed files with 16 additions and 0 deletions
|
@ -1,4 +1,7 @@
|
|||
{{- template "hrefhack" . -}}
|
||||
{{ with .Site.GetPage .Site.Params.BookMenuBundle }}
|
||||
{{- .Content -}}
|
||||
{{ end }}
|
||||
{{ if .Site.Params.BookEnableJS }}
|
||||
{{- template "jsmenu" . -}}
|
||||
{{ end }}
|
|
@ -23,4 +23,17 @@
|
|||
color: {{ default "#004ed0" .Site.Params.BookMenuBundleActiveLinkColor }};
|
||||
}
|
||||
</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 }}
|
Loading…
Reference in a new issue