Skip to content

Commit

Permalink
Decode TOC link
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed May 29, 2020
1 parent 4013450 commit 0d2b3af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/js/utils.js
Expand Up @@ -237,10 +237,10 @@ NexT.utils = {
const navItems = document.querySelectorAll('.post-toc li');
const sections = [...navItems].map(element => {
const link = element.querySelector('a.nav-link');
const target = document.getElementById(decodeURI(link.getAttribute('href')).replace('#', ''));
// TOC item animation navigate.
link.addEventListener('click', event => {
event.preventDefault();
const target = document.getElementById(event.currentTarget.getAttribute('href').replace('#', ''));
const offset = target.getBoundingClientRect().top + window.scrollY;
window.anime({
targets : document.scrollingElement,
Expand All @@ -249,7 +249,7 @@ NexT.utils = {
scrollTop: offset + 10
});
});
return document.getElementById(link.getAttribute('href').replace('#', ''));
return target;
});

const tocElement = document.querySelector('.post-toc-wrap');
Expand Down

0 comments on commit 0d2b3af

Please sign in to comment.