【发布时间】:2015-02-09 15:13:26
【问题描述】:
我在正确滚动时无法使用 scrollspy 插件来跟踪我的活动状态。我正在使用 scrollspy.js 库。我愿意优化插件,例如在某些偏移量中发生状态变化。我在插件中找不到任何选项来执行 OffsetTop,因为我相信这会解决问题。下面是我的 HTML 结构和初始化插件的 javascript。
<div class="faq_tabs hidden_faq_tabs">
<div id="my-nav">
<ul class="stickyMenu">
<li>
<a href="#general" data-spyer="general">General</a>
</li>
<li>
<a href="#student" data-spyer="student">Student</a>
</li>
<li>
<a href="#business" data-spyer="business">Business</a>
</li>
</ul>
</div>
</div>
<div>
<h1 id="general" class="spyon">GENERAL</h1>
</div>
<div>
<h1 id="student" class="spyon">STUDENT</h1>
</div>
<div>
<h1 id="business" class="spyon">BUSINESS</h1>
</div>
我已经定制了如下所示的脚本来获取数据属性以添加活动类。
$('.spyon').scrollSpy();
$('.spyon').on('scrollSpy:enter', function(){
$('[data-spyer="' + $(this).attr('id') + '"]').addClass('spyedon');
});
$('.spyon').on('scrollSpy:exit', function(){
$('[data-spyer="' + $(this).attr('id') + '"]').removeClass('spyedon');
});
这是我使用插件的演示:
http://frakton.com/scholarbiz-v1.2/?id=22
在提供的链接中,您可以看到错误。我愿意避免前两个项目的活动状态。
【问题讨论】: