hexo使用next主题博客侧边栏标题点击不跳转
hexo版本5.0.2 npm版本6.14.7 next版本7.8.0
本着我肯定不是第一个出这个问题的人,去github上找了找,果然我不是第一个
好吧,也跟着改吧(修改themes/next/source/js/utils.js),找到registerSidebarTOC函数
registerSidebarTOC: function() {
const navItems = document.querySelectorAll('.post-toc li');
const sections = [...navItems].map(element => {
var link = element.querySelector('a.nav-link');
// 修复侧边栏 标题点击不跳转问题
var target = document.getElementById(decodeURI(link.getAttribute('href')).replace('#', ''));
// TOC item animation navigate.
link.addEventListener('click', event => {
event.preventDefault();
//var target = document.getElementById(event.currentTarget.getAttribute('href').replace('#', ''));
var offset = target.getBoundingClientRect().top + window.scrollY;
window.anime({
targets : document.scrollingElement,
duration : 500,
easing : 'linear',
scrollTop: offset + 10
});
});
//return document.getElementById(link.getAttribute('href').replace('#', ''));
return target;
});
参考文献
标签:hexo,博客,next,link,侧边,跳转,document From: https://www.cnblogs.com/life-time/p/18469191