|
10 | 10 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css">
|
11 | 11 | <link rel="stylesheet" href="https://unpkg.com/boxicons@latest/css/boxicons.min.css">
|
12 | 12 | <link rel="stylesheet" type="text/css" href="~/Styles/site.css" />
|
13 |
| - <script> |
14 |
| - document.addEventListener("DOMContentLoaded", function() { |
15 |
| - var sidebar = document.getElementById("sidebar"); |
16 |
| - if (sidebar) { |
17 |
| - // Restore scroll position |
18 |
| - var scrollPosition = sessionStorage.getItem("sidebarScrollPosition"); |
19 |
| - if (scrollPosition) { |
20 |
| - sidebar.scrollTop = scrollPosition; |
21 |
| - } |
22 |
| - |
23 |
| - // Save scroll position |
24 |
| - sidebar.addEventListener("scroll", function () { |
25 |
| - sessionStorage.setItem("sidebarScrollPosition", sidebar.scrollTop); |
26 |
| - }); |
| 13 | +<script> |
| 14 | + document.addEventListener("DOMContentLoaded", function () { |
| 15 | + var sidebar = document.getElementById("sidebar"); |
| 16 | + if (sidebar) { |
| 17 | + // Restore scroll position |
| 18 | + var scrollPosition = sessionStorage.getItem("sidebarScrollPosition"); |
| 19 | + if (scrollPosition) { |
| 20 | + sidebar.scrollTop = scrollPosition; |
27 | 21 | }
|
28 |
| - }); |
29 | 22 |
|
30 |
| - // Function to clear scroll position |
31 |
| - function clearScrollPosition() { |
32 |
| - sessionStorage.removeItem("sidebarScrollPosition"); |
| 23 | + // Save scroll position |
| 24 | + sidebar.addEventListener("scroll", function () { |
| 25 | + sessionStorage.setItem("sidebarScrollPosition", sidebar.scrollTop); |
| 26 | + }); |
| 27 | + |
| 28 | + // Scroll to the active button if not visible |
| 29 | + var activeButton = sidebar.querySelector("li.active a"); |
| 30 | + if (activeButton) { |
| 31 | + var rect = activeButton.getBoundingClientRect(); |
| 32 | + var sidebarRect = sidebar.getBoundingClientRect(); |
| 33 | + if (rect.top < sidebarRect.top || rect.bottom > sidebarRect.bottom) { |
| 34 | + activeButton.scrollIntoView({ behavior: "smooth", block: "center" }); |
| 35 | + } |
| 36 | + } |
33 | 37 | }
|
34 |
| - </script> |
| 38 | + }); |
| 39 | + |
| 40 | + // Function to clear scroll position |
| 41 | + function clearScrollPosition() { |
| 42 | + sessionStorage.removeItem("sidebarScrollPosition"); |
| 43 | + } |
| 44 | +</script> |
35 | 45 | </head>
|
36 | 46 | <body>
|
37 | 47 | <form id="form1" runat="server">
|
|
0 commit comments