File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Scroll the active navigation item into view on page load
3+ */
4+ ( function ( ) {
5+ 'use strict' ;
6+
7+ function scrollActiveNavIntoView ( ) {
8+ // Find the active navigation item in the sidebar
9+ const activeNavItem = document . querySelector ( '.site-navigation__entry.active' ) ;
10+
11+ if ( activeNavItem ) {
12+ // Scroll it into view with some padding
13+ activeNavItem . scrollIntoView ( {
14+ behavior : 'auto' ,
15+ block : 'center' ,
16+ inline : 'nearest'
17+ } ) ;
18+ }
19+ }
20+
21+ // Run when DOM is ready
22+ if ( document . readyState === 'loading' ) {
23+ document . addEventListener ( 'DOMContentLoaded' , scrollActiveNavIntoView ) ;
24+ } else {
25+ // DOM is already ready
26+ scrollActiveNavIntoView ( ) ;
27+ }
28+ } ) ( ) ;
Original file line number Diff line number Diff line change 4545 < script type ="text/javascript " src ="{{ get_url(path='mobile-menu.js') }} "> </ script >
4646 < script type ="text/javascript " src ="{{ get_url(path='dark-mode.js') }} "> </ script >
4747 < script type ="text/javascript " src ="{{ get_url(path='sidebar-toggle.js') }} "> </ script >
48+ < script type ="text/javascript " src ="{{ get_url(path='scroll-active-nav.js') }} "> </ script >
4849 < script type ="text/javascript " src ="{{ get_url(path='copy-code.js') }} " defer > </ script >
4950 < script type ="text/javascript " src ="{{ get_url(path='elasticlunr.min.js') }} " defer > </ script >
5051 < script type ="text/javascript " src ="{{ get_url(path='api_search.js') }} " defer > </ script >
You can’t perform that action at this time.
0 commit comments