Exclude ID in Twitter Bootstrap Scrollspy

后端 未结 2 850
渐次进展
渐次进展 2020-12-18 18:06

I have a Twitter Bootstrap site with a main menu full of links. I have Scrollspy setup to target that menu and works great.

However, I need scrollspy to exclude the

2条回答
  •  不知归路
    2020-12-18 18:18

    I'm not aware of any "easy" fix for your situation. However you can use the "activate" event to check for the ID and act upon it:

    $('#myscrollspyID li').on('activate',  function(){
         var id = $(this).find("a").attr("href");
         if (id === "#yourlastID"){
              //do something, i.e. remove all active classes from your scrollspy object, so  none are shown as active
         }
    }
    

    P.S: this i pretty rough code, but I modified some code I am using myself. I use the active event to check the ID of the active item, and change the background color of the navigator bar to the color corresponding to the active item :-)

提交回复
热议问题