File tree 1 file changed +16
-1
lines changed 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 147
147
148
148
var self = this ;
149
149
150
+ self . tocifyWrapper = $ ( '.tocify-wrapper' ) ;
150
151
self . extendPageScroll = true ;
151
152
152
153
// Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings)
703
704
// Highlights the corresponding list item
704
705
elem . addClass ( self . focusClass ) ;
705
706
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
+ }
706
721
}
707
722
708
723
if ( self . options . scrollHistory ) {
1021
1036
1022
1037
} ) ;
1023
1038
1024
- } ) ) ; //end of plugin
1039
+ } ) ) ; //end of plugin
You can’t perform that action at this time.
0 commit comments