mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
parent
4013450403
commit
0d2b3af50b
@ -237,10 +237,10 @@ NexT.utils = {
|
|||||||
const navItems = document.querySelectorAll('.post-toc li');
|
const navItems = document.querySelectorAll('.post-toc li');
|
||||||
const sections = [...navItems].map(element => {
|
const sections = [...navItems].map(element => {
|
||||||
const link = element.querySelector('a.nav-link');
|
const link = element.querySelector('a.nav-link');
|
||||||
|
const target = document.getElementById(decodeURI(link.getAttribute('href')).replace('#', ''));
|
||||||
// TOC item animation navigate.
|
// TOC item animation navigate.
|
||||||
link.addEventListener('click', event => {
|
link.addEventListener('click', event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const target = document.getElementById(event.currentTarget.getAttribute('href').replace('#', ''));
|
|
||||||
const offset = target.getBoundingClientRect().top + window.scrollY;
|
const offset = target.getBoundingClientRect().top + window.scrollY;
|
||||||
window.anime({
|
window.anime({
|
||||||
targets : document.scrollingElement,
|
targets : document.scrollingElement,
|
||||||
@ -249,7 +249,7 @@ NexT.utils = {
|
|||||||
scrollTop: offset + 10
|
scrollTop: offset + 10
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return document.getElementById(link.getAttribute('href').replace('#', ''));
|
return target;
|
||||||
});
|
});
|
||||||
|
|
||||||
const tocElement = document.querySelector('.post-toc-wrap');
|
const tocElement = document.querySelector('.post-toc-wrap');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user