File tree Expand file tree Collapse file tree 1 file changed +8
-16
lines changed
Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Original file line number Diff line number Diff line change 2626 * Detect the active page in the sidebar, and scroll so that it is centered on
2727 * the screen.
2828 */
29- var scrollToActive = ( ) => {
30- var navbar = document . getElementById ( "site-navigation" ) ;
31- var navbar_scrollable = navbar . children [ 0 ] ;
32- var active_pages = navbar . querySelectorAll ( ".active" ) ;
33- var active_page = active_pages [ active_pages . length - 1 ] ;
34- // Only scroll the navbar if the active link is lower than 50% of the page
35- if (
36- active_page !== undefined &&
37- active_page . offsetTop > $ ( window ) . height ( ) * 0.5
38- ) {
39- navbar_scrollable . scrollTop =
40- active_page . offsetTop - $ ( window ) . height ( ) * 0.2 ;
29+
30+ var scrollToActive = ( ) => {
31+ let navbar_scrollable = $ ( "#site-navigation" ) . children ( ) [ 0 ] ;
32+ let active_navigation_item = $ ( "#site-navigation .active" ) . last ( ) ;
33+ if ( active_navigation_item ) {
34+ if ( active_navigation_item . offset ( ) . top > $ ( window ) . height ( ) * 0.5 ) {
35+ navbar_scrollable . scrollTop = active_navigation_item . offset ( ) . top - $ ( window ) . height ( ) * 0.2 ;
36+ }
4137 }
4238} ;
4339
4440
4541sbRunWhenDOMLoaded ( scrollToActive ) ;
46-
47- $ ( document ) . ready ( function ( ) {
48- console . debug ( "debug patch_scrollToActive" )
49- } ) ;
You can’t perform that action at this time.
0 commit comments