提交 a314dc03 编写于 作者: EvanOne(文一)'s avatar EvanOne(文一)

fix: Toc highlighting is incorrect

上级 0026d9d6
...@@ -18,7 +18,7 @@ $(document).ready(function () { ...@@ -18,7 +18,7 @@ $(document).ready(function () {
var currHeading = null; var currHeading = null;
// The heading that reached the top last time. // The heading that reached the top last time.
var lastHeading = null; var lastHeading = null;
var isRemoveTocClass = false; var isRemovedTocClass = false;
// Automatically expand items in the article directory // Automatically expand items in the article directory
// based on the scrolling of heading in the article. // based on the scrolling of heading in the article.
...@@ -43,25 +43,22 @@ $(document).ready(function () { ...@@ -43,25 +43,22 @@ $(document).ready(function () {
if ( if (
$postBody[0] && $postBody[0] &&
$firsetChild[0] && $firsetChild[0] &&
$firsetChild[0].getBoundingClientRect().top > 0 &&
$firsetChild.offset().top - $(window).scrollTop() > 0 $firsetChild.offset().top - $(window).scrollTop() > 0
) { ) {
if (!isRemoveTocClass) { if (!isRemovedTocClass) {
$allTocItem.removeClass('active current'); $allTocItem.removeClass('active current');
isRemoveTocClass = true; isRemovedTocClass = true;
} }
return; return;
} }
if (currHeading !== lastHeading) { if (currHeading !== lastHeading) {
var $targetLink = $('.sidebar-toc a[href="#' + currHeading + '"]'); var $targetLink = $('.sidebar-toc a[href="#' + currHeading + '"]');
// If the relevant "<a>" is not found, remain the state of the toc, $allTocItem.removeClass('active current');
// either, remove styles for all active states.
if ($targetLink[0]) {
$allTocItem.removeClass('active current');
}
$targetLink.parents('li').addClass('active'); $targetLink.parents('li').addClass('active');
$targetLink.parent().addClass('current'); $targetLink.parent().addClass('current');
lastHeading = currHeading; lastHeading = currHeading;
isRemovedTocClass = false;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册