Skip to content

Commit

Permalink
Scroll into view sidebar (#3376)
Browse files Browse the repository at this point in the history
Signed-off-by: James Hunt <[email protected]>
  • Loading branch information
thetwopct authored Dec 30, 2024
1 parent 01253b7 commit 879b6c7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions layouts/partials/sidebar-tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</form>
<div class="search-by-tag">
<a href="{{ relref . "/tags" }}">{{ T "ui_or_search_by_tags" }}</a>
</div>
</div>
{{ else -}}
<div id="content-mobile">
<form class="td-sidebar__search d-flex align-items-center">
Expand Down Expand Up @@ -74,4 +74,20 @@
</ul>
{{- end }}
</li>
{{- end }}
{{- end }}

<script>
document.addEventListener("DOMContentLoaded", function () {
const sidebar = document.querySelector("#td-section-nav");
const activeLink = sidebar?.querySelector(".td-sidebar-nav__section .active");

if (activeLink && sidebar) {
const sidebarTop = sidebar.scrollTop;
const activeLinkOffset = activeLink.offsetTop;
sidebar.scrollTo({
top: activeLinkOffset - sidebar.clientHeight / 2 + activeLink.offsetHeight / 2,
behavior: "smooth",
});
}
});
</script>

0 comments on commit 879b6c7

Please sign in to comment.