首页 > 其他分享 >博客搭建之路:hexo使用next主题博客侧边栏标题点击不跳转

博客搭建之路:hexo使用next主题博客侧边栏标题点击不跳转

时间:2024-10-16 10:00:37浏览次数:1  
标签:hexo 博客 next link 侧边 跳转 document

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

相关文章

  • TowardsDataScience-博客中文翻译-2021-二十四-
    TowardsDataScience博客中文翻译2021(二十四)原文:TowardsDataScienceBlog协议:CCBY-NC-SA4.0从头开始编码线性回归原文:https://towardsdatascience.com/coding-linear-regression-from-scratch-c42ec079902?source=collection_archive---------0-----------------------......
  • TowardsDataScience-博客中文翻译-2021-二十六-
    TowardsDataScience博客中文翻译2021(二十六)原文:TowardsDataScienceBlog协议:CCBY-NC-SA4.0意甲(足球)——带有Plotly和Dash的简单仪表盘原文:https://towardsdatascience.com/create-a-simple-dashboard-with-plotly-dash-8f385ba1dd6d?source=collection_archive--......
  • TowardsDataScience-博客中文翻译-2020-一百二十九-
    TowardsDataScience博客中文翻译2020(一百二十九)原文:TowardsDataScienceBlog协议:CCBY-NC-SA4.0什么是机器学习?—直观的解释。原文:https://towardsdatascience.com/what-is-machine-learning-a-visual-explanation-14642b90429f?source=collection_archive---------25--......
  • 一个基于若依的超级漂亮的博客系统,可用于所有Web应用(带私活源码)
     今天分享的开源项目是:RuoYiBlog-一个基于若依的超级漂亮的博客系统 。一、项目介绍     如果你一直想做一个博客平台,看过许多优秀的开源项目,但没有找到合适的,那么今天可以参考这个项目。作者利用业余时间把若依后台管理和pb-cms结合起来,在自己的参考中开发了一......
  • 【CTF Web】Pikachu 不安全的url跳转 Writeup(URL重定向+代码审计)
    不安全的url跳转不安全的url跳转问题可能发生在一切执行了url地址跳转的地方。如果后端采用了前端传进来的(可能是用户传参,或者之前预埋在前端页面的url地址)参数作为了跳转的目的地,而又没有做判断的话就可能发生"跳错对象"的问题。url跳转比较直接的危害是:–>钓鱼,......
  • TowardsDataScience-博客中文翻译-2020-四十五-
    TowardsDataScience博客中文翻译2020(四十五)原文:TowardsDataScienceBlog协议:CCBY-NC-SA4.0基于Avro模式的类固醇弹性研究原文:https://towardsdatascience.com/elasticsearch-on-steroids-with-avro-schemas-3bfc483e3b30?source=collection_archive---------30------......
  • TowardsDataScience-博客中文翻译-2020-五十五-
    TowardsDataScience博客中文翻译2020(五十五)原文:TowardsDataScienceBlog协议:CCBY-NC-SA4.0GPT-3,OpenAI的革命原文:https://towardsdatascience.com/gpt-3-openais-revolution-f549bf3d4b25?source=collection_archive---------43-----------------------来源:弗洛里......
  • TowardsDataScience-博客中文翻译-2020-三-
    TowardsDataScience博客中文翻译2020(三)原文:TowardsDataScienceBlog协议:CCBY-NC-SA4.0做出更好决策的3个要素原文:https://towardsdatascience.com/3-essentials-to-make-better-decisions-9b2cdc60365e?source=collection_archive---------47-----------------------......
  • WebSecurityConfigurerAdapter 关于成功之后页面跳转的配置
    packagecom.feitai.auth.config;importcom.feitai.manager.PtfUserDetailsManager;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.context.annotation.Configuration;importorg.springframework.security.config.annota......
  • 基于nodejs+vue基于springboot的个人博客设计与实现[开题+源码+程序+论文]计算机毕业
    本系统(程序+源码+数据库+调试部署+开发环境)带文档lw万字以上,文末可获取源码系统程序文件列表开题报告内容研究背景随着互联网技术的飞速发展和信息时代的到来,个人表达与分享的需求日益增长。博客作为一种重要的网络应用形式,为博主提供了展示自我、分享知识与见解的平台。......