如何使用bootstrap scrollspy将类添加到活动菜单项?

时间:2015-04-01 06:46:29

标签: javascript jquery twitter-bootstrap navigation

我正在使用此代码,但它并不像我期望的那样工作。

$("#myNavbar").on("activate.bs.scrollspy", function(){
    $(this).parent('li').addClass('hvr-overline-reveal');
    var currentItem = $(".nav li.active > a");
    currentItem.parent("li").addClass("hvr-pulse");
    currentItem.addClass("hvr-overline-reveal");
}) 
});

主要问题是:

$("#myNavbar").on("activate.bs.scrollspy", function(){
}

滚动页面时会激活jQuery。如何在li元素出现时向其中添加一个类?

https://jsfiddle.net/Hnk9W/12/

1 个答案:

答案 0 :(得分:0)

使用此代码

$('body').scrollspy({ target: '#navbar-example' });

用导航栏替换导航栏示例 阅读文档:http://getbootstrap.com/javascript/#scrollspy