Skip to content

Commit

Permalink
adding scroll position helper (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrying authored Oct 13, 2023
1 parent 9d43299 commit acd47b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 14 additions & 0 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ Array.from(searchForms).forEach(container => {
}
});

const menuPositioner = () => {
const nav = document.querySelectorAll("#sidebar-default")[1]
const itemActive = document.querySelectorAll(".sidebar-item-active")
const itemActiveMobile = document.querySelectorAll(".offcanvas-body .sidebar-item-active")
const navMobile = document.querySelector(".offcanvas-body")

if (itemActive.length) {
nav.scrollTop = itemActive[itemActive.length - 1].offsetTop - 300
navMobile.scrollTop = itemActiveMobile[itemActiveMobile.length - 1].offsetTop - 200
}
}

menuPositioner()

window.addEventListener('load', function() {
index = new FlexSearch.Document({
tokenize: "forward",
Expand Down
3 changes: 0 additions & 3 deletions layouts/partials/footer/script-footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
{{ $slice = $slice | append $katexConfig -}}
{{ end -}}

{{ $scrollLock := resources.Get "js/scroll-lock.js" | js.Build -}}
{{ $slice = $slice | append $scrollLock -}}

{{ $js := $slice | resources.Concat "main.js" -}}

{{ if eq (hugo.Environment) "development" -}}
Expand Down

0 comments on commit acd47b8

Please sign in to comment.