Improve scripts for menu-scroll

- also fixes menu-scroll-position not working in search page
This commit is contained in:
Aditya Telange 2021-04-29 19:02:59 +05:30
parent 2f409920e1
commit 43e1648b3e
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77
2 changed files with 5 additions and 9 deletions

View File

@ -23,14 +23,10 @@
{{- partial "extend_footer.html" . }}
<script>
window.onload = function () {
if (localStorage.getItem("menu-scroll-position")) {
document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position");
}
}
function menu_on_scroll() {
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
let menu = document.getElementById('menu')
menu.scrollLeft = localStorage.getItem("menu-scroll-position");
menu.onscroll = function () {
localStorage.setItem("menu-scroll-position", menu.scrollLeft);
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => {

View File

@ -139,7 +139,7 @@
</span>
</div>
{{- $currentPage := . }}
<ul id="menu" onscroll="menu_on_scroll()">
<ul id="menu">
{{- range .Site.Menus.main }}
{{- $menu_item_url := (cond (strings.HasSuffix .URL "/") .URL (printf "%s/" .URL) ) | absLangURL }}
{{- $page_url:= $currentPage.Permalink | absLangURL }}