【问题标题】:jQuery waypoint not firing on first itemjQuery航点未在第一项上触发
【发布时间】:2013-11-17 15:33:05
【问题描述】:

我正在使用waypoint.js 来检测某些<div>s 何时滚动过去,并在它们滚动时更改导航类。这是我的 HTML:

<div class="section" id="section1">
  Some text
</div>
<div class="section" id="section1">
  More text
</div>

<ul id="nav">
  <li><a href="#" id="trigger1">Go to section 1</a></li>
  <li><a href="#" id="trigger2">Go to section 2</a></li>
</ul>

这里是 jQuery:

$('.section').waypoint(function(){

    var id = $(this).attr('id').replace('section','');
    $('ul#nav li a').removeClass('current');
    $('#trigger'+id).addClass('current');

});

这工作,向下和向上滚动,除了当我向右滚动回到顶部时,第二个菜单项仍然突出显示(仍然有 current 类),而返回到顶部 应该 em> 突出显示第一个菜单项。任何想法我做错了什么?

谢谢。

【问题讨论】:

    标签: jquery html jquery-waypoints


    【解决方案1】:

    你有两次 id="section1" 也许这会导致问题?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多