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{
6969if ( top == TOC . lastTop ) return ;
7070TOC . lastTop = top ;
7171
72- let minDiff = 1000000000 , current = null ;
72+ let minDiff = 1000000000 , currentId = null ;
7373for ( let section of TOC . sections ) {
7474let ot = section . offsetTop - 50 ;
7575if ( ot > top ) continue ;
7676let diff = top - ot ;
7777if ( diff < minDiff ) {
7878minDiff = 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 ) {
8385if ( TOC . lastLi != null ) TOC . lastLi . classList . remove ( 'current' ) ;
84- TOC . lastLi = document . getElementById ( 'li_' + current . id ) ;
86+ TOC . lastLi = currentLi || null ;
8587if ( TOC . lastLi != null ) TOC . lastLi . classList . add ( 'current' ) ;
8688}
8789}
You can’t perform that action at this time.
0 commit comments