0
点赞
收藏
分享

微信扫一扫

next主题侧边目录点击失效无法正常跳转

夏沐沐 2022-03-11 阅读 15

next主题侧边目录点击失效无法正常跳转

错误描述:

1.点击侧边栏目录无法正常跳转;

2.控制台报错:Uncaught TypeError: Cannot read properties of undefined (reading 'top')

报错文件:post-details.js?v=5.1.4:76

报错文件路径:\themes\next\source\js\src\post-details.js

解决办法:

1.知道是post-details.js文件报错后就简单了,阅读源码之后我们发现是targetSelector解析 UTF8 有问题;

在文件的72行左右:

  // TOC item animation navigate & prevent #item selector in adress bar.
  $('.post-toc a').on('click', function (e) {
    e.preventDefault();
    <!-- targetSelector 解析UTF8的问题 ->
    var targetSelector = NexT.utils.escapeSelector(this.getAttribute('href'));
    var offset = $(targetSelector).offset().top;

    hasVelocity ?
      html.velocity('stop').velocity('scroll', {
        offset: offset  + 'px',
        mobileHA: false
      }) :
      $('html, body').stop().animate({
        scrollTop: offset
      }, 500);
  });

解决:

// 将 targetSelector 再解析一次就好了

var targetSelector = NexT.utils.escapeSelector(this.getAttribute('href'));
    <!-- 添加下面这行代码, 重新解析 URL ->
    targetSelector = decodeURI(this.getAttribute('href')) 	// 需要添加的代码加在75行左右	
    var offset = $(targetSelector).offset().top;
举报

相关推荐

0 条评论