Twitter Bootstrap Scrollspy始终突出显示最后一个元素

时间:2016-07-13 05:39:27

标签: jquery html css twitter-bootstrap

我无法弄清楚出了什么问题以及为什么在滚动时只选择了最后一部分。

<body data-spy="scroll" data-target="#homeToolbar" data-offset="50">
  <nav class="navbar navbar-default navbar-fixed-top" id="homeToolbar">
    <div class="container-fluid">
      <div class="navbar-header">
        <a class="navbar-brand" href="#">Testing</a>
      </div>
      <div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav pull-right">
            <li><a href="#section2">Home</a></li>
            <li><a href="#section3">Product</a></li>
            <li><a href="#section4">Team</a></li>
            <li><a href="#section5">Contact</a></li>
          </ul>
        </div>
      </div>
    </div>
  </nav>
</body>

1 个答案:

答案 0 :(得分:1)

Check this working fiddle

尝试使用。词缀的功能和一些偏移量,并将 .page-scroll 类添加到要滚动的元素。

你的Jquery应该有点像这样(基于上面的小提琴)

//jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {

// jQuery for page scrolling feature - requires jQuery Easing plugin
$('a.page-scroll').bind('click', function(event) {
    var $anchor = $(this);
    $('html, body').stop().animate({
        scrollTop: ($($anchor.attr('href')).offset().top - 50)
    }, 1250, 'easeInOutExpo');
    event.preventDefault();
});

// Highlight the top nav as scrolling occurs
$('body').scrollspy({
    target: '.navbar-fixed-top',
    offset: 51
});

// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a:not(.dropdown-toggle)').click(function() {
    $('.navbar-toggle:visible').click();
});

// Offset for Main Navigation
$('#mainNav').affix({
    offset: {
        top: 100
    }
});

});
相关问题