Skip to content

Commit

Permalink
Update toc null error
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Sep 8, 2023
1 parent ee07bb2 commit e2dd792
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ if (toc) {

for (var i = 0; i < tocItems.length; i++) {
let item = tocItems[i];
var targetBounds = item.target.getBoundingClientRect();

if( targetBounds.bottom > windowHeight * TOP_MARGIN && targetBounds.top < windowHeight * ( 1 - BOTTOM_MARGIN ) ) {
visibleItems += 1;
item.listItem.classList.add( 'toc-active' );
atLeastOne = true;
} else {
item.listItem.classList.remove( 'toc-active' );
}
if (item.target) {

var targetBounds = item.target.getBoundingClientRect();

if( targetBounds.bottom > windowHeight * TOP_MARGIN && targetBounds.top < windowHeight * ( 1 - BOTTOM_MARGIN ) ) {
visibleItems += 1;
item.listItem.classList.add( 'toc-active' );
atLeastOne = true;
} else {
item.listItem.classList.remove( 'toc-active' );
}

if (targetBounds.bottom < windowHeight) {
lastElem = item;
if (targetBounds.bottom < windowHeight) {
lastElem = item;
}
}

}
Expand Down

0 comments on commit e2dd792

Please sign in to comment.