File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -69,19 +69,21 @@ class TOC {
6969 if ( top == TOC . lastTop ) return ;
7070 TOC . lastTop = top ;
7171
72- let minDiff = 1000000000 , current = null ;
72+ let minDiff = 1000000000 , currentId = null ;
7373 for ( let section of TOC . sections ) {
7474 let ot = section . offsetTop - 50 ;
7575 if ( ot > top ) continue ;
7676 let diff = top - ot ;
7777 if ( diff < minDiff ) {
7878 minDiff = diff ;
79- current = section ;
79+ currentId = section . id ;
8080 }
8181 }
82- if ( TOC . lastLi != current ) {
82+
83+ let currentLi = currentId ? document . querySelector ( `#li_${ currentId } ` ) : null ;
84+ if ( TOC . lastLi != currentLi ) {
8385 if ( TOC . lastLi != null ) TOC . lastLi . classList . remove ( 'current' ) ;
84- TOC . lastLi = document . getElementById ( 'li_' + current . id ) ;
86+ TOC . lastLi = currentLi || null ;
8587 if ( TOC . lastLi != null ) TOC . lastLi . classList . add ( 'current' ) ;
8688 }
8789 }
You can’t perform that action at this time.
0 commit comments