javascript - 自定义 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'); } }); }); });
这是我使用此代码的实时页面:演示页面
解决方案
谢谢伪装我得到了这个问题。侧边栏菜单中的最后一个链接没有与任何框相关联,因为它会导致问题。谢谢 :)
推荐阅读
- android - 广播接收器不工作(没有被调用)
- r - 将值从一个数据帧搜索到另一个数据帧
- momentjs - 时刻 fromNow() 但仅到某个点
- python - Sci kit 学习混淆矩阵总是看起来几乎一样
- c# - 在 c# 中使用 var 被认为是不好的做法吗?
- python - Folium Choropleth,pandas 的问题:GeoJSON 引发 AttributeError: 'NoneType'
- php - 来自地址的php邮件(Net / SMTP.php)不起作用
- python - 需要帮助使用 Keras 的 model.predict
- php - 致命错误:未捕获的 PDO 异常:SQLSTATE[42000] 语法错误或访问违规
- python - 一次获得一个要与一个敌人战斗的敌人列表