diff options
author | Jeffrey Tse <jeffreytse.mail@gmail.com> | 2019-09-24 15:19:05 +0800 |
---|---|---|
committer | Jeffrey Tse <jeffreytse.mail@gmail.com> | 2019-09-24 15:19:05 +0800 |
commit | bc91aa6b7360bf520fd7e0f7a61a934c4d20ea33 (patch) | |
tree | dfe8ec88056fd2283f12e0656d32e056bd86cc6a /_includes/extensions | |
parent | 4b70145bedae98e8dc2d34b8e83eca0c669bad87 (diff) |
fix: corrcet hash locate, menu item hilight issues
Diffstat (limited to '_includes/extensions')
-rw-r--r-- | _includes/extensions/hashlocate.html | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/_includes/extensions/hashlocate.html b/_includes/extensions/hashlocate.html index 6faf553..5194273 100644 --- a/_includes/extensions/hashlocate.html +++ b/_includes/extensions/hashlocate.html @@ -7,18 +7,21 @@ return; } - var header = document.querySelector('header'); + var header = document.querySelector('header.site-header'); + var headerRect = header.getBoundingClientRect(); + var headerTop = Math.floor(headerRect.top); + var headerHeight = Math.floor(headerRect.height); var scrollPos = getScrollPos(); - var offsetY = element.offsetTop - (header.offsetTop + header.offsetHeight + 20); + var offsetY = element.offsetTop - (headerTop + headerHeight + 20); - if (offsetY == scrollPos.y) { + if (offsetY == scrollPos.y) { return; } - if (header.offsetTop == 0 && offsetY > scrollPos.y) { - offsetY += header.offsetHeight; - } else if (header.offsetTop < 0 && offsetY < scrollPos.y) { - offsetY -= header.offsetHeight; + if (headerTop == 0 && offsetY > scrollPos.y) { + offsetY += headerHeight + 2; + } else if (headerTop < 0 && offsetY < scrollPos.y) { + offsetY -= headerHeight - 2; } smoothScrollTo(offsetY); |