首页 > 解决方案 > 自定义 Scrollspy 在我的网页上不起作用

问题描述

我写了一些代码来突出显示页面的当前链接。但问题是它没有通过使用“activem”类突出显示侧边栏菜单链接项。我无法找出我做错的问题。下面是代码:

这是网站的jquery部分:

$(document).ready(function() {

var scrollLink = $('.scroll');

// Smooth scrolling
scrollLink.click(function(e) {
  e.preventDefault();
  $('body,html').animate({
    scrollTop: $(this.hash).offset().top-80
  }, 1000 );
});


// Active link switching
$(window).scroll(function() {
  var scrollbarLocation = $(this).scrollTop();

  scrollLink.each(function() {

    var sectionOffset = $(this.hash).offset().top - 20;

    if ( sectionOffset <= scrollbarLocation ) {
      $(this).addClass('activem');
      $(this).siblings().removeClass('activem');
    }
  });

});

});

这是我使用此代码的实时页面:演示页面

标签: javascriptjquery

解决方案


谢谢伪装我得到了这个问题。侧边栏菜单中的最后一个链接没有与任何框相关联,因为它会导致问题。谢谢 :)


推荐阅读