#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
|
@ -2,3 +2,6 @@
|
|||
{{ with .Site.GetPage .Site.Params.BookMenuBundle }}
|
||||
{{- .Content -}}
|
||||
{{ end }}
|
||||
{{ if .Site.Params.BookEnableJS }}
|
||||
{{- template "jsmenu" . -}}
|
||||
{{ end }}
|
|
@ -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 }}
|
Loading…
Reference in a new issue