File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 147147
148148 var self = this ;
149149
150+ self . tocifyWrapper = $ ( '.tocify-wrapper' ) ;
150151 self . extendPageScroll = true ;
151152
152153 // Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings)
703704 // Highlights the corresponding list item
704705 elem . addClass ( self . focusClass ) ;
705706
707+ // Scroll to highlighted element's header
708+ var tocifyWrapper = self . tocifyWrapper ;
709+ var scrollToElem = $ ( elem ) . closest ( '.tocify-header' ) ;
710+
711+ var elementOffset = scrollToElem . offset ( ) . top ,
712+ wrapperOffset = tocifyWrapper . offset ( ) . top ;
713+ var offset = elementOffset - wrapperOffset ;
714+
715+ if ( offset >= $ ( window ) . height ( ) ) {
716+ var scrollPosition = offset + tocifyWrapper . scrollTop ( ) ;
717+ tocifyWrapper . scrollTop ( scrollPosition ) ;
718+ } else if ( offset < 0 ) {
719+ tocifyWrapper . scrollTop ( 0 ) ;
720+ }
706721 }
707722
708723 if ( self . options . scrollHistory ) {
10211036
10221037 } ) ;
10231038
1024- } ) ) ; //end of plugin
1039+ } ) ) ; //end of plugin
You can’t perform that action at this time.
0 commit comments